2
$\begingroup$

I am trying to make a figure with four plots using Grid[]. I added some padding to accommodate the FrameLabels but I would like to remove only the right padding and yet keep the four Plots with the same size.

Code:

imgpad = {{60, 60}, {60, 10}};
figa = Plot[x, {x, 0, 10}, ImageSize -> 500, ImagePadding -> imgpad];
figb = Plot[x, {x, 0, 10}, ImageSize -> 500, ImagePadding -> imgpad];
figc = Plot[x, {x, 0, 10}, ImageSize -> 500, ImagePadding -> imgpad];
figd = Plot[x, {x, 0, 10}, ImageSize -> 500, ImagePadding -> imgpad];
grid = Grid[{{figa, figb}, {figc, figd}}, Spacings -> 0]

enter image description here

If I change the imgpag to {{60, 10}, {60, 10}}, the space in the middle is also removed, which I don't want. How can I remove only the space on the right without changing the size of the plots?

Edit: These are the correct paddings. I need them to be exactly like this, but the plots need to be the same size.

Code:

figa=Plot[x,{x,0,10},ImageSize->500,ImagePadding->{{60,60},{60,10}}];
figb=Plot[x,{x,0,10},ImageSize->500,ImagePadding->{{60,10},{60,10}}];
figc=Plot[x,{x,0,10},ImageSize->500,ImagePadding->{{60,60},{60,10}}];
figd=Plot[x,{x,0,10},ImageSize->500,ImagePadding->{{60,10},{60,10}}];
grid=Grid[{{figa,figb},{figc,figd}},Spacings->0]

Output:

enter image description here

$\endgroup$
3
$\begingroup$

Update 2: Use the form ImageSize -> 1 -> 50 for setting image size:

figa = Plot[x, {x, 0, 10}, ImageSize -> 1 -> 50, ImagePadding -> {{60, 60}, {60, 10}}];
figb = Plot[x, {x, 0, 10}, ImageSize -> 1 -> 50, ImagePadding -> {{60, 10}, {60, 10}}];
figc = Plot[x, {x, 0, 10}, ImageSize -> 1 -> 50, ImagePadding -> {{60, 60}, {60, 10}}];
figd = Plot[x, {x, 0, 10}, ImageSize -> 1 -> 50, ImagePadding -> {{60, 10}, {60, 10}}];

grid = Grid[{{figa, figb}, {figc, figd}}, Spacings -> 0]

enter image description here

Update:

imgpad = {{60, 10}, {60, 10}};
ClearAll[figa, figb, figc, figd]
figa = figb = figc = figd = 
     Plot[x, {x, 0, 10}, ImageSize -> 1 -> 50, ImagePadding -> imgpad];

Framed @ Grid[
  MapAt[Replace[#, HoldPattern[ImagePadding -> p_] :> 
      ImagePadding -> (p + {{50, 0}, {0, 0}}), All] &,
       {{figa, figb}, {figc, figd}}, {All, 2}], 
  Spacings -> 0]

enter image description here

Original answer:

imgpad = {{60, 10}, {60, 10}};

figa = figb = figc = figd = 
  Plot[x, {x, 0, 10}, ImageSize -> 500, ImagePadding -> imgpad];

Framed @ Grid[{{figa, figb}, {figc, figd}}, Spacings -> {5, 0}]

enter image description here

$\endgroup$
5
  • $\begingroup$ Unfortunately, this won't work. The space in the middle is there, but it crops the extra FrameLabel that I need to add to the graphs on the left. Maybe you could crop the right space after the complete image is generated? $\endgroup$
    – Rodrigo
    Nov 7 '20 at 22:25
  • $\begingroup$ @Rodrigo, please see the update. $\endgroup$
    – kglr
    Nov 7 '20 at 22:45
  • $\begingroup$ The padding {{60, 60}, {60, 10}} is required for figa and figc, while for figb and figd is {{60, 10}, {60, 10}}. I am adding an extra axis on the right side of figa and figc so I need that extra padding. The problem is if I set different paddings, the plots change sizes. Your update is almost correct, but it still crops the right side of figa and figc. $\endgroup$
    – Rodrigo
    Nov 7 '20 at 23:37
  • $\begingroup$ @Rodrigo, it would help a lot if you updated your question with a more detailed example. $\endgroup$
    – kglr
    Nov 7 '20 at 23:57
  • $\begingroup$ I added more details. Basically I need that padding and the plots need to be the same size. $\endgroup$
    – Rodrigo
    Nov 8 '20 at 1:03
1
$\begingroup$

I found a workaround. Cropped the right extra space after the Grid is generated :)

Code:

imgpad={{60,60},{60,10}};
cropGraphics[g_,x_,y_,w_,h_]:=Graphics[Inset[g,{x,y},{0,0}],PlotRange->{{0,1},{0,1}},ImageSize->{w,h},AspectRatio->Full]
figa=Plot[x,{x,0,10},ImageSize->500,ImagePadding->imgpad];
figb=Plot[x,{x,0,10},ImageSize->500,ImagePadding->imgpad];
figc=Plot[x,{x,0,10},ImageSize->500,ImagePadding->imgpad];
figd=Plot[x,{x,0,10},ImageSize->500,ImagePadding->imgpad];
grid=Grid[{{figa,figb},{figc,figd}},Spacings->0];
cropGraphics[grid,0.525,0.5,950,617]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.