필터 지우기
필터 지우기

Plot multiple time ranges on a single line?

조회 수: 3 (최근 30일)
Weston Hustace
Weston Hustace 2023년 2월 2일
댓글: Weston Hustace 2023년 2월 5일
Hello,
I have a Nx2 timetable of start (column 1) and end (column 2) times, read from a csv file. Each of these time ranges describe a session of data collection for location 'A' An example is this:
A =
'04/19/0022 14:37' '04/19/0022 22:49'
'05/03/0022 14:47' '05/03/0022 23:01'
'05/17/0022 16:58' '05/17/0022 23:02'
'05/31/0022 15:02' '05/31/0022 23:07'
'06/14/0022 14:33' '06/14/0022 23:03'
'10/26/0022 23:28' '10/28/0022 14:14'
'11/02/0022 23:58' '11/04/0022 00:18'
'11/14/0022 17:07' '11/16/0022 01:11'
How might I best plot this data in a time series so each collection session shows as a bar/whisker line on one horizontial axis within the plot?
Additionally, if I had another location and associated variable, 'B', how would I add this second horizontial line with sessions into the graph?
I've drawn an example here (the times don't match to the above data):
I have considered Gantt charts but this seems to be built more specifically towards different mixing of 'A' and 'B' between the horizontial planes.
Thank you.

채택된 답변

Kyoung Moon Lee
Kyoung Moon Lee 2023년 2월 3일
I have created a code based on the values you wrote down and the picture attached.
You can edit this code by adding the data you need.
%% data
A = {
'04/19/2022 14:37' '04/19/2022 22:49'
'05/03/2022 14:47' '05/03/2022 23:01'
'05/17/2022 16:58' '05/17/2022 23:02'
'05/31/2022 15:02' '05/31/2022 23:07'
'06/14/2022 14:33' '06/14/2022 23:03'
'10/26/2022 23:28' '10/28/2022 14:14'
'11/02/2022 23:58' '11/04/2022 00:18'
'11/14/2022 17:07' '11/16/2022 01:11'};
for ii = 1:height(A)
dnum(ii,1) = datenum(A{ii,1});
dnum(ii,2) = datenum(A{ii,2});
end
%% figure
figure()
for ii = 1:height(A)
% set
hold on;
x = [dnum(ii,1) dnum(ii,2)];
y = [6 6];
% plot
plot(x,y,'k','LineWidth',5)
% deco
xlim([dnum(1,1) dnum(end,2)])
datetick('x','mm-dd','keeplimits','keeplimits')
xlabel('mm-dd (2022)')
ylim([0 10])
yticks([4 6])
yticklabels({'B','A'})
end
  댓글 수: 1
Weston Hustace
Weston Hustace 2023년 2월 5일
Thank you! That helped me move in the right direction and your code was a great sample.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by