How to change Y-axis in subplots of Boxplot on the same figure
이전 댓글 표시
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
답변 (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.
댓글 수: 1
Yaser Khojah
2020년 3월 4일
편집: Yaser Khojah
2020년 3월 4일
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!