How to chose the correct line style?

2 ビュー (過去 30 日間)
Louise Wilson
Louise Wilson 2021 年 7 月 21 日
回答済み: Jonas 2021 年 7 月 22 日
I have created the attached plot. I have a large dataset with multiple entries, each representing different moving objects. I want to draw a line plotting the movement of each unique object, per day. This works, but the display is different depending on whether I use scatter or plot. If I use plot, I get the type of line I would like, where the lines are connected, but using scatter, solitary points (that aren't moving) are missed from the plot. How do I choose a line style which allows me to show both the solitary points and connect those points that are related?
For example, I see that I could just plot one of each line style over the top of each other, but then I lose the unique colours attached to each set of data points.
subplot(5,1,1)
unique_MMSI=unique(gps_data.cpa3);
for i=1:height(unique_MMSI)
MMSI=unique_MMSI(i);
S=gps_data.cpa3==MMSI;
gps_sub=gps_data(S,:);
[N,edges,bin] = histcounts(datetime(gps_sub.cpa1,'ConvertFrom','datenum'),'BinMethod','day');
bin_num=unique(bin);
bin_num=bin_num';
for ii=1:width(bin_num)
bin_on=bin_num(ii);
[lia,loc]=ismember(bin,bin_on);
gps_plot=gps_sub(lia,:);
gps_plot.DateTime=datetime(gps_plot.cpa1,'ConvertFrom','datenum');
plot(gps_plot.DateTime,gps_plot.vessel_CPAs)
hold on
end
hold on
end
ylim([0 5])
starttime=datetime(2020,1,1,0,0,0);
endtime=datetime(2020,6,7,0,0,0);
xlim([starttime, endtime]);
xticks(starttime:days(7):endtime); %change range of x-axis using times from .wav
xlim([starttime, endtime]);
xtickangle(0);
  3 件のコメント
Louise Wilson
Louise Wilson 2021 年 7 月 21 日
Thanks Jonas! That solved it. I didn't realise, thank you!
Jonas
Jonas 2021 年 7 月 22 日
great to hear it was what you were searching for. i will post the comment as answer below, you can then accept it and then this forum has one question less to be solved

サインインしてコメントする。

回答 (1 件)

Jonas
Jonas 2021 年 7 月 22 日
looks like you have to add a marker to your plot atcommand, then you do not only have lines but also markers during and the ends of the lines

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by