Creating a specific time subplot
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rachel Cox
le 28 Nov 2022
Réponse apportée : Seth Furman
le 28 Nov 2022
Hello
Im plotting time and wave height and im trying to plot a graph shpwing yearly trends but highlighting February and march and then a subplot of just february and march. So far I have highlighted the two months in different olours (trying to make them both red) and my subplot just shows march.
figure(1)
for m=1:12
V.H.Time = data{1,m}{1,1}(:,1);
V.H.Hm0 = data{1,m}{1,2}(:,6);
subplot(2,1,1)
plot(V.H.Time,V.H.Hm0)
hold on
plot(V.H.Time,V.H.Hm0, 'k') %keep one figure open and add extra data open (stops multiple figures)
hold on
m=4
V.H.Time = data{1,m}{1,1}(:,1);
V.H.Hm0 = data{1,m}{1,2}(:,6);
plot(V.H.Time,V.H.Hm0)
m=8
V.H.Time = data{1,m}{1,1}(:,1);
V.H.Hm0 = data{1,m}{1,2}(:,6);
plot(V.H.Time,V.H.Hm0)
plot(V.H.Time,V.H.Hm0, 'r')
datetick('x','mmm','keeplimits')
hold on
subplot(2,1,2)
m=4
plot(V.H.Time,V.H.Hm0)
m=8
plot(V.H.Time,V.H.Hm0)
hold on
plot(V.H.Time,V.H.Hm0, 'r')
datetick('x','mmm','keeplimits')
end
0 commentaires
Réponse acceptée
Plus de réponses (1)
Seth Furman
le 28 Nov 2022
To color each month, you can use stackedplot and provide multiple timetables
tt = timetable(datetime(2022,1,1)+hours(0:24*365-1)',cos(linspace(0,2*pi,24*365)'+randn(24*365,1)/10))
janToMarch = tt(1 <= tt.Time.Month & tt.Time.Month <= 3,:);
aprilToJune = tt(4 <= tt.Time.Month & tt.Time.Month <= 6,:);
sp = stackedplot(janToMarch, aprilToJune);
then use colororder
colororder(sp, ["black","#EDB120"]);
To create multiple subplots, you can use tiledlayout
months = cell(1,12);
for i = 1:numel(months)
months{i} = tt(tt.Time.Month == i,:);
end
tl = tiledlayout(2,1);
nexttile;
stackedplot(months, LegendVisible="off");
nexttile;
stackedplot(months(2:3), LegendLabels=["February","March"]);
0 commentaires
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!