TransWikia.com

Remove extra space from Grid

Mathematica Asked on May 22, 2021

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

2 Answers

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

Correct answer by kglr on May 22, 2021

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

Answered by Rodrigo on May 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP