How can I increase the vertical size of subplots?

조회 수: 49 (최근 30일)
NA
NA 2020년 6월 8일
댓글: Star Strider 2020년 6월 8일
Hi,
I'm trying to increase the verticle size of my subplots, but I'm having no luck. Can someone please let me know where I've gone wrong.
My code is:
suplotTitle = {'0.4mA', '0.6mA', '0.8mA', '1.2mA', '1.6mA'};
f1=figure('position', [10, 10, 800, 1000]);
for ii=1:5
subplot(6,2,2*ii-1);
b1 = bar(conRR(2:end,1), conRR(2:end,ii+1));
b1.FaceColor = '#D95319';
b1.EdgeColor = 'none';
xticks(1:1:16);
ylim([0 80]);
title(suplotTitle{ii})
set(gca, 'FontSize', 10);
box off
if ii < 5
set(gca,'XTick', []);
end
end
subplot(6,2,5), ylabel('Respiratory Rate (BPM)')
subplot(6,2,9), xlabel('Number of rats (N)')
for ii=1:5
s2 = subplot(6,2,2*ii);
b2 = bar(b9RR(2:end,1), b9RR(2:end,ii+1));
b2.FaceColor = '#0072BD';
b2.EdgeColor = 'none';
xticks(1:1:16);
ylim([0 80]);
title(suplotTitle{ii})
box off
set(gca, 'FontSize', 10);
if ii < 5
set(gca,'XTick', []);
end
end
subplot(6,2,6), ylabel('Respiratory Rate (BPM)');
subplot(6,2,10), xlabel('Number of rats (N)');
%Add legend
hL = subplot(6,2,[11,12]);
poshL = get(hL,'position');
lgd = legend(hL,[b1,b2],'Control','Intervention');
legend box off;
set(lgd,'position',poshL,'Orientation','horizontal', 'FontSize', 12);
axis(hL,'off'); % Turning its axis off
%Add main title
t = sgtitle('Respiratory Rate');
t.FontSize = 15;
t.FontWeight = 'bold';
At the moment my Figure looks like this:
Thanks in advance.
  댓글 수: 2
Paresh yeole
Paresh yeole 2020년 6월 8일
Try using :
set(gca,'Units','centimeters','Position', [0 0 7.5 6])
for each subplot.
NA
NA 2020년 6월 8일
thank you

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 6월 8일
I got this to work with the previous code, however I couldn’t get it to work with the code you posted. You will need to make the appropriate adjustments to do that.
The change is to add these two lines in each looop:
PosVec = Ax.Position;
Ax.Position = PosVec+[0 -0.005 0 0.005];
and after both loops:
f1.Position = f1.Position+[0 -300 0 300];
That should get you started.
The (Revised) Code —
conRR = [(0:10).' rand(11,5)*80]; % Create Matrix
b9RR = [(0:10).' rand(11,5)*80]; % Create Matrix
suplotTitle = {'0.4mA', '0.6mA', '0.8mA', '1.2mA', '1.6mA'};
f1=figure
for ii=1:5
Ax = subplot(5,2,2*ii-1);
b1 = bar(conRR(2:end,1), conRR(2:end,ii+1));
b1.FaceColor = '#D95319';
b1.EdgeColor = 'none';
xticks(1:1:16);
ylim([0 80]);
title(suplotTitle{ii})
PosVec = Ax.Position;
Ax.Position = PosVec+[0 -0.005 0 0.005];
end
for ii=1:5
Ax = subplot(5,2,2*ii);
b2 = bar(b9RR(2:end,1), b9RR(2:end,ii+1));
b2.FaceColor = '#0072BD';
b2.EdgeColor = 'none';
xticks(1:1:16);
ylim([0 80]);
title(suplotTitle{ii})
PosVec = Ax.Position;
Ax.Position = PosVec+[0 -0.005 0 0.005];
end
f1.Position = f1.Position+[0 -300 0 300];
The Plots —
Original:
This code:
  댓글 수: 2
NA
NA 2020년 6월 8일
편집: NA 2020년 6월 8일
Thanks Star Strider. The subplots look great, but I couldn't figure out how to add the x-y-labels and the legend with my current code. I'd always get an error for some reason. But nevertheless, I found a way around it - I just created a legend with the data from my subplots and then manually positioned them. This seemed to work relatively well - good enough to present the data at tomorrow's meeting anyway! Thanks again!
Star Strider
Star Strider 2020년 6월 8일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2020년 6월 8일
You can manually adjust the subplot's axes position like this:
sph = subplot(3,2,1);
dx0 = 0;
dy0 = -0.05;
dwithx = 0.0;
dwithy = 0.1;
set(sph,'position',get(sph,'position')+[dx0,dy0,dwithx,dwithy])
You will have to modify this heavily, but the tweaking shouldn't be too bad for one figure - and might be "impossible" to get right for an absolutely general sub-plots configuration.
There are a number of file-exchange contributions that handles this, or different parts of this:
Hopfully you find something useful.
HTH

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by