How to chose the correct line style?

조회 수: 3 (최근 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에서 Data Distribution Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by