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 CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by