How to reverse one of the y-axis in a stackedplot?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2023-3-13
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 个评论
Star Strider
2023-3-13
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.)
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

