Creating a specific time subplot
조회 수: 7 (최근 30일)
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Seth Furman
2022년 11월 28일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!