Plot multiple time ranges on a single line?

6 visualizaciones (últimos 30 días)
Weston Hustace
Weston Hustace el 2 de Feb. de 2023
Comentada: Weston Hustace el 5 de Feb. de 2023
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.

Respuesta aceptada

Kyoung Moon Lee
Kyoung Moon Lee el 3 de Feb. de 2023
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 comentario
Weston Hustace
Weston Hustace el 5 de Feb. de 2023
Thank you! That helped me move in the right direction and your code was a great sample.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by