How to reduce horizontal distance between plots on 2x2 plot figure?

1 visualización (últimos 30 días)
AmericanExpat26
AmericanExpat26 el 2 de Dic. de 2016
Respondida: Iddo Weiner el 2 de Dic. de 2016
I used subplot to create a 2x2 figure grid and then stacked the 2 pairs vertically because each pair uses the same x-axis. The figures will included in a publication so I need to get them to fit within the margins of a word document without sacrificing their resolution. The summary of the present code I am using now is given below:
h1 = subplot(2,2,1)
h2 = subplot(2,2,3)
p1 = get(h1,'Position');
p2 = get(h2,'Position');
p1(2) = p2(2) + p2(4);
set(h1,'pos',p1);
Then:
h3 = subplot(2,2,2)
h4 = subplot(2,2,3)
p3 = get(h3,'Position');
p4 = get(h4,'Position');
p3(2) = p4(2) + p4(4);
set(h3,'pos',p3);
I have also used the position vectors of the plot objects to close the vertical distance between plots using something like:
p1 = get(h1,'Position');
p2 = get(h2,'Position');
p2(2) = p2(2)*1.35;
p2(3) = p1(3);
set(h2,'pos',p2);
Can something similar be done with the position vectors to close the horizontal distance between the plots even if though the vertical position has already been modified? Figure is given below as well. Thanks.

Respuestas (1)

Iddo Weiner
Iddo Weiner el 2 de Dic. de 2016
Try the following idea (might help, depends on the exact requirements of the journal etc.) - instead of going
subplot(2,2,1) ... subplot(2,2,4)
try defining subplot(M,N,Xi) - where M,N are the dimensions of the plot (and I will suggest setting them to an integer larger than 2), and Xi is a vector defining the location of subplot i (in your case: i=1:4). Here's an example in which M=N=4 :
figure
subplot(4,4,[1,2,5,6])
bar(normrnd(0,1,100,1))
subplot(4,4,[3,4,7,8])
histogram(normrnd(0,1,100,1))
subplot(4,4,[9,10,13,14])
bar(normrnd(0,1,100,1))
subplot(4,4,[11,12,15,16])
histogram(normrnd(0,1,100,1))
Now, you can play around with M and N (don't forget to adjust the range accordingly). This won't actually change the absolute dimensions of the whole figure but it will get rid of the horizontal space between the columns. Hope this helps

Community Treasure Hunt

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

Start Hunting!

Translated by