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

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);
Accepted Answer
More Answers (1)
Peter Perkins
on 13 Jun 2022
0 votes
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 Comment
Farbod Tabaei
on 17 Jun 2022
Categories
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!