How to adjust the same size of each subplot in one figure?

1 visualización (últimos 30 días)
Hi,
I am now stucked in how to how to adjust the same size of each subplot in one figure.
As we can see in below:
The leftmost and rightmost subplots are wider than the middle subplots and how should I do to matain all the subplots as the same size?
Here is the code:
b = xlsread('table' , 'single process', 'E5:L94');
for i = 1:1:15
%FD_(M)
x1(i,1) = b(( i-1)*6+1,1); %n = 30
x2(i,1) = b(( i-1)*6+2,1);
x3(i,1) = b(( i-1)*6+3,1);
x4(i,1) = b(( i-1)*6+4,1);
x5(i,1) = b(( i-1)*6+5,1);
x6(i,1) = b(( i-1)*6+6,1);
%FD*
x7(i,1) = b(( i-1)*6+1,2); %n = 30
x8(i,1) = b(( i-1)*6+2,2);
x9(i,1) = b(( i-1)*6+3,2);
x10(i,1) = b(( i-1)*6+4,2);
x11(i,1) = b(( i-1)*6+5,2);
x12(i,1) = b(( i-1)*6+6,2);
%SB
x13(i,1) = b(( i-1)*6+1,3); %n = 30
x14(i,1) = b(( i-1)*6+2,3);
x15(i,1) = b(( i-1)*6+3,3);
x16(i,1) = b(( i-1)*6+4,3);
x17(i,1) = b(( i-1)*6+5,3);
x18(i,1) = b(( i-1)*6+6,3);
%PB
x19(i,1) = b(( i-1)*6+1,4); %n = 30
x20(i,1) = b(( i-1)*6+2,4);
x21(i,1) = b(( i-1)*6+3,4);
x22(i,1) = b(( i-1)*6+4,4);
x23(i,1) = b(( i-1)*6+5,4);
x24(i,1) = b(( i-1)*6+6,4);
%BCPB
x25(i,1) = b(( i-1)*6+1,5); %n = 30
x26(i,1) = b(( i-1)*6+2,5);
x27(i,1) = b(( i-1)*6+3,5);
x28(i,1) = b(( i-1)*6+4,5);
x29(i,1) = b(( i-1)*6+5,5);
x30(i,1) = b(( i-1)*6+6,5);
%GCI
x31(i,1) = b(( i-1)*6+1,6); %n = 30
x32(i,1) = b(( i-1)*6+2,6);
x33(i,1) = b(( i-1)*6+3,6);
x34(i,1) = b(( i-1)*6+4,6);
x35(i,1) = b(( i-1)*6+5,6);
x36(i,1) = b(( i-1)*6+6,6);
%MC(G)
x37(i,1) = b(( i-1)*6+1,6); %n = 30
x38(i,1) = b(( i-1)*6+2,6);
x39(i,1) = b(( i-1)*6+3,6);
x40(i,1) = b(( i-1)*6+4,6);
x41(i,1) = b(( i-1)*6+5,6);
x42(i,1) = b(( i-1)*6+6,6);
%MC(A)
x43(i,1) = b(( i-1)*6+1,6); %n = 30
x44(i,1) = b(( i-1)*6+2,6);
x45(i,1) = b(( i-1)*6+3,6);
x46(i,1) = b(( i-1)*6+4,6);
x47(i,1) = b(( i-1)*6+5,6);
x48(i,1) = b(( i-1)*6+6,6);
end
x = [x1 x7 x13 x19 x25 x31 x37 x43
x2 x8 x14 x20 x26 x32 x38 x44
x3 x9 x15 x21 x27 x33 x39 x45
x4 x10 x16 x22 x28 x34 x40 x46
x5 x11 x17 x23 x29 x35 x41 x47
x6 x12 x18 x24 x30 x36 x42 x48
];
c1 = [x1 x7 x13 x19 x25 x31 x37 x43 ]; c2=[ x2 x8 x14 x20 x26 x32 x38 x44 ]; c3 = [x3 x9 x15 x21 x27 x33 x39 x45 ]; c4 = [ x4 x10 x16 x22 x28 x34 x40 x46];
c5 = [ x5 x11 x17 x23 x29 x35 x41 x47]; c6 = [x6 x12 x18 x24 x30 x36 x42 x48];
subplot(1,6,1);
boxplot(c1,'labels',{'FD(M)','FD*','SB','PB','BCPB','GCI','MC(G)','MC(A)'})
xlabel('n = 30');
ylabel('Coverage Rate');
%set(gca, 'position', [0.167 0.11 100 100]);
axis([0.25 8.5 0.825 0.995]);
line([0.25 8.5],[0.9173 0.9173],'LineWidth',1.75)
line([0.25 8.5],[0.9000 0.9000],'LineStyle','--')
line([0.25 8.5],[0.8827 0.8827],'LineWidth',1.75)
subplot(1,6,2);
boxplot(c2,'labels',{'FD(M)','FD*','SB','PB','BCPB','GCI','MC(G)','MC(A)'} )
xlabel('n = 40');
ylabel('Coverage Rate');
%set(gca,'fontsize',8)
axis([0.25 8.5 0.825 0.995]);
line([0.25 8.5],[0.9173 0.9173],'LineWidth',1.75)
line([0.25 8.5],[0.9000 0.9000],'LineStyle','--')
line([0.25 8.5],[0.8827 0.8827],'LineWidth',1.75)
subplot(1,6,3);
boxplot(c3,'labels',{'FD(M)','FD*','SB','PB','BCPB','GCI','MC(G)','MC(A)'} )
xlabel('n = 50');
ylabel('Coverage Rate');
%set(gca,'fontsize',8)
axis([0.25 8.5 0.825 0.995]);
line([0.25 8.5],[0.9173 0.9173],'LineWidth',1.75)
line([0.25 8.5],[0.9000 0.9000],'LineStyle','--')
line([0.25 8.5],[0.8827 0.8827],'LineWidth',1.75)
subplot(1,6,4);
boxplot(c4,'labels',{'FD(M)','FD*','SB','PB','BCPB','GCI','MC(G)','MC(A)'} )
xlabel('n = 100');
ylabel('Coverage Rate');
%set(gca,'fontsize',8)
axis([0.25 8.5 0.825 0.995]);
line([0.25 8.5],[0.9173 0.9173],'LineWidth',1.75)
line([0.25 8.5],[0.9000 0.9000],'LineStyle','--')
line([0.25 8.5],[0.8827 0.8827],'LineWidth',1.75)
subplot(1,6,5);
boxplot(c5,'labels',{'FD(M)','FD*','SB','PB','BCPB','GCI','MC(G)','MC(A)'} )
xlabel('n = 150');
ylabel('Coverage Rate');
%set(gca,'fontsize',8)
axis([0.25 8.5 0.825 0.995]);
line([0.25 8.5],[0.9173 0.9173],'LineWidth',1.75)
line([0.25 8.5],[0.9000 0.9000],'LineStyle','--')
line([0.25 8.5],[0.8827 0.8827],'LineWidth',1.75)
subplot(1,6,6);
boxplot(c6,'labels',{'FD(M)','FD*','SB','PB','BCPB','GCI','MC(G)','MC(A)'} )
xlabel('n = 200');
ylabel('Coverage Rate');
%set(gca,'fontsize',8)
axis([0.25 8.5 0.825 0.995]);
line([0.25 8.5],[0.9173 0.9173],'LineWidth',1.75)
line([0.25 8.5],[0.9000 0.9000],'LineStyle','--')
line([0.25 8.5],[0.8827 0.8827],'LineWidth',1.75)
I know it is a little lengthy but sincerely hope you can give me the instruction to solve my problem.
Thanks!
  6 comentarios
Walter Roberson
Walter Roberson el 18 de Mayo de 2019
Editada: Walter Roberson el 18 de Mayo de 2019
There is no command for that purpose.
However, if you were to attach the .xls or .xlsx then someone could test to find out why you are not getting evenly spaced subplots,
Chao-Zhen Liu
Chao-Zhen Liu el 18 de Mayo de 2019
Editada: Chao-Zhen Liu el 18 de Mayo de 2019
Hi, Walter
Below is the Google drive link:
Hope you can give me some advice, thanks!

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Mayo de 2019
I confirm that subplot() allocates different OuterPosition widths for different subplots -- even just for empty graphs. However it seems to do a good job of allocating the same initial InnerPosition even though the OuterPositions vary.
But... given the exact same content, the InnerPositions are not all the same width, and the OuterPositions are still notably different.
It looks like given the different c* data, that the InnerPosition values might come out the same as if the same data was plotted in each. One must, though, expect that if the tick labels happened to come out different widths (due to different data) that there could be differences.
If you try simple experiments such as subplot(1,2,1);subplot(1,2,2) and then look at their OuterPosition and total them up, you can see that they do not cover the entire figure: whitespace is being left somewhere. The amount of whitespace left depends on the number of subplots, and does not increase or decrease according to any obvious logic.
So... it appears that to get evenly spaced, that one is going to have to calculate the OuterPosition for each plot instead of using subplot() .

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by