# Creating a specific time subplot

조회 수: 3 (최근 30일)
Rachel Cox 2022년 11월 28일
답변: Seth Furman 2022년 11월 28일
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

댓글을 달려면 로그인하십시오.

### 채택된 답변

VBBV 2022년 11월 28일
%hold on. Comment this line
subplot(2,1,2)
Comment the line above
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Rachel Cox 2022년 11월 28일
I'm unsure what this means

댓글을 달려면 로그인하십시오.

### 추가 답변 (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))
tt = 8760×1 timetable
Time Var1 ____________________ _______ 01-Jan-2022 00:00:00 0.9978 01-Jan-2022 01:00:00 0.99909 01-Jan-2022 02:00:00 0.98911 01-Jan-2022 03:00:00 0.98734 01-Jan-2022 04:00:00 0.99889 01-Jan-2022 05:00:00 0.9869 01-Jan-2022 06:00:00 0.99972 01-Jan-2022 07:00:00 0.98416 01-Jan-2022 08:00:00 0.95042 01-Jan-2022 09:00:00 0.99574 01-Jan-2022 10:00:00 0.99892 01-Jan-2022 11:00:00 0.9827 01-Jan-2022 12:00:00 0.99661 01-Jan-2022 13:00:00 0.99449 01-Jan-2022 14:00:00 0.99796 01-Jan-2022 15:00:00 0.99166
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"]);

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by