How to change Y-axis in subplots of Boxplot on the same figure
7 次查看(过去 30 天)
显示 更早的评论
I need help with creating 4 boxplots in one figure where in each subplot I would like to assign the ylim. In this example, the ylim looks nice and no need to change it but in my model I want to change it. Thanks for your help in advance.
% this is just an example and in my code the values vary more. Thus, need to change the ylim in each plot.
r1 = 10*rand(5);
r2 = 100*rand(6);
r3 = 1000*rand(7);
r4 = 10000*rand(8);
r = {r1, r2, r3, r4};
for i = 1:4
subplot1 = subplot(4,1,i);
boxplot(r{i}); hold on
ylim()
end
0 个评论
回答(1 个)
Jakob B. Nielsen
2020-3-4
You need a reference back to each inidividual subplot. Right now, your subplot1 label is overwritten each time, so you can only refer back to your 4th and final plot. Index it, so you get a reference to all four subplot axes.
r1 = 10*rand(5);
r2 = 100*rand(6);
r3 = 1000*rand(7);
r4 = 10000*rand(8);
r = {r1, r2, r3, r4};
for i = 1:4
subplot1(i) = subplot(4,1,i); %this turns subplot1 into a 1x4 axes
boxplot(r{i}); hold on
end
ylim(subplot(1),[0 100]) %just for example.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!