How to reverse one of the y-axis in a stackedplot?
2 views (last 30 days)
Show older comments
I was able to obtain a stackedplot using 2 tables each containing different sets of data. However, I would like reverse tbl1's y axis so there are lower values at the top and higher values at the bottom, rather than vice versa, which is what automatically shows up.
Here is an example of the stacked plot:
stackedplot(tbl1, tbl2, 'XVariable',["x1", "x2"])
How do I reverse the y-axis of tbl1 in this stackedplot?
0 Comments
Accepted Answer
Star Strider
on 13 Mar 2023
I doubt that’s possible, since the AxesProperties property doesn’t include YDir.
load outdoors
outdoors(1:3,:)
s = stackedplot(outdoors);
% get(s)
s.AxesProperties
An alternative would be tiledlayout, since it has sepaarate axes thet can be individually controlled —
VN = outdoors.Properties.VariableNames;
figure
tiledlayout(3,1)
for k = 1:3
nexttile
plot(outdoors.Time, outdoors{:,k})
ylabel(VN{k})
end
xlabel('Time')
hf = get(gcf);
Kids1 = get(hf.Children);
Kids2 = Kids1.Children;
Kids2(1).YDir = 'reverse'; % Reverse Y-Axis On Third Plot
That is likely the only option.
.
2 Comments
Star Strider
on 13 Mar 2023
As always, my pleasure!
Sure!
To completely understand it, you need to remove the end semicolons from ‘Kids1’ and ‘Kids2’ to see what they return. Specifically, ‘Kids2’ returns handles to the three (here) Axes objects created by stackedplot. They all have the expected set of Properties that can then be set, including YDir. (The Axes handles are created in the reverse order in which they appear, so the first one is the last listed Axes handle, and the last listed is the first Axes handle. If the stackedplot array has more than one column, the Axes handles go column-wise and then row-wise, so row 1 column 1, row 1 column2 ... row 2 column 1 row 2 column 2 ... etc. although they appear as a vector. Again, the last listed is the first created.)
.
More Answers (0)
See Also
Categories
Find more on Printing and Saving 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!
