Plot multiple time ranges on a single line?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!