24 hour time line plot for discrete data
Afficher commentaires plus anciens
How to create a 24 hour time line plot for discrete data that can be color coded like the following image?

Summer Winter 0:00 7.7 6.4 1:00 7.7 6.4 2:00 7.7 6.4 3:00 7.7 6.4 4:00 7.7 6.4 5:00 7.7 6.4 6:00 12.2 21.7 7:00 12.2 21.7 8:00 12.2 7.8 9:00 12.2 7.8 10:00 12.2 7.8 11:00 12.2 7.8 12:00 12.2 7.8 13:00 12.2 7.8 14:00 12.2 7.8 15:00 40.5 7.8 16:00 40.5 7.8 17:00 40.5 7.8 18:00 40.5 21.7 19:00 12.2 21.7 20:00 12.2 7.8 21:00 12.2 7.8 22:00 7.7 6.4 23:00 7.7 6.4
Réponses (1)
Star Strider
le 21 Août 2026 à 4:54
Modifié(e) : Star Strider
le 21 Août 2026 à 5:05
The contourf function can get you there. You can choose the appropriate colormap or create your own.
Try something like this --
Summer_Winter = ["0:00 7.7 6.4 1:00 7.7 6.4 2:00 7.7 6.4 3:00 7.7 6.4 4:00 7.7 6.4 5:00 7.7 6.4 6:00 12.2 21.7 7:00 12.2 21.7 8:00 12.2 7.8 9:00 12.2 7.8 10:00 12.2 7.8 11:00 12.2 7.8 12:00 12.2 7.8 13:00 12.2 7.8 14:00 12.2 7.8 15:00 40.5 7.8 16:00 40.5 7.8 17:00 40.5 7.8 18:00 40.5 21.7 19:00 12.2 21.7 20:00 12.2 7.8 21:00 12.2 7.8 22:00 7.7 6.4 23:00 7.7 6.4"]
tc = regexp(Summer_Winter, '\d+:\d+', 'match');
TimeTable = table(datetime(tc,InputFormat='HH:mm', Format='HH:mm').');
% disp(Timestr)
SW = regexp(Summer_Winter, '\d*\.\d*', 'match');
SWT = str2double(reshape(SW, 2, [])).';
Summer_Winter_T = [TimeTable array2table(SWT)];
Summer_Winter_T.Properties.VariableNames={'Time','Summer','Winter'}
Slvls = [0; sort(unique(Summer_Winter_T.Summer))];
Wlvls = [0; sort(unique(Summer_Winter_T.Winter))];
figure
surf(hour(Summer_Winter_T.Time)*[1 1], ones(size(Summer_Winter_T,1),2).*[1 2], Summer_Winter_T.Summer*[1 1])
colormap(turbo)
title('Summer (Surface Plot)')
figure
contourf(hour(Summer_Winter_T.Time)*[1 1], ones(size(Summer_Winter_T,1),2).*[2.5 3.0], Summer_Winter_T.Summer*[1 1], Slvls)
hold on
contourf(hour(Summer_Winter_T.Time)*[1 1], ones(size(Summer_Winter_T,1),2).*[1.5 2.0], Summer_Winter_T.Winter*[1 1], Wlvls)
hold off
colormap(turbo)
ylim('padded')
xlabel('Clock Time')
yticks([1.75 2.75])
Ax = gca;
% get(Ax)
yticklabels(Ax,{'Winter','Summer'})
See the contourf documentation for details.
EDIT -- (21 Aug 2026 at 05:05)
Added Slvls and Wlvls.
.
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

