フィルターのクリア

Stacked plots: display two variables on the same x-axis

40 ビュー (過去 30 日間)
Farbod Tabaei
Farbod Tabaei 2022 年 6 月 7 日
コメント済み: Voss 2022 年 6 月 20 日
Hello everyone,
I am trying to make a stacked plot of multiple variables, with the middle plot having two y-axes (please refer to the picture for clarification). I am having trouble setting the second y-axis on the right side and "VPD" is showing as a straight line since its values are much smaller than "PAR". The "VPD" is planned to be plotted as a bar plot. Here is the code that I am using:
T_Variables = table(date,Ta, PAR, VPD, REW, Ts_5cm, 'VariableNames' , {'Date' 'Ta','PAR','VPD','REW','Ts'});
TT_Variables = table2timetable(T_Variables);
TT_Variables_Monthly = retime(TT_Variables, 'monthly' , 'mean');
degreeSymbol = char(176);
newYlabels = ["Ta (" + degreeSymbol + "C)","PAR (umol/m2/s)","REW"];
Vars = {'Ta',{'PAR','VPD'},'REW'};
c = stackedplot(TT_Variables_Monthly,Vars,"Title","Stacked Plot","DisplayLabels",newYlabels);

採用された回答

Voss
Voss 2022 年 6 月 18 日
You can use subplot/tiledlayout with yyaxis, and then set the relevant axes properties to make the display more like what you get with stackedplot.
% using subplot:
ax = [ ...
subplot(3,1,1) ...
subplot(3,1,2) ...
subplot(3,1,3) ...
];
% using tiledlayout:
% t = tiledlayout(3,1);
% ax = [ ...
% nexttile(t) ...
% nexttile(t) ...
% nexttile(t) ...
% ];
% the code below works the same whether
% using subplot or tiledlayout:
plot(ax(1),rand(1,50))
yyaxis(ax(2),'left')
plot(ax(2),100*cos(1:75))
yyaxis(ax(2),'right')
plot(ax(2),sin(1:85))
plot(ax(3),rand(1,100))
linkaxes(ax,'x')
set(ax,'Box','off')
xax = get(ax(1:2),'XAxis');
set([xax{:}],'Visible','off')
yax = get(ax(2),'YAxis');
set(yax(1),'Color','k')
  2 件のコメント
Farbod Tabaei
Farbod Tabaei 2022 年 6 月 20 日
Your codes on subplots will be extremely useful, thanks a lot!
Voss
Voss 2022 年 6 月 20 日
You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2022 年 6 月 13 日
Farbod, IIUC, you cannot do that with stackedplot. Each subplot can have only one y axis. The whole point of stackedplot is to align multiple variables along their time axis, but for them to have separate y axes so the scaling doesn't cause the very issue you are running into. I suggest you let stackedplot make four subplots.
  1 件のコメント
Farbod Tabaei
Farbod Tabaei 2022 年 6 月 17 日
Thanks for your explanation Peter. Much appreciated!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by