I am having problems joining multiple plots using GraphicsRow and GraphicsGrid. The issue is that Mathematica (v12.1) rescales arbitrarily my plots when I try to combine them. The issue arises when I try to combine the output of GraphicsGrid with another plot using again GraphicsGrid/GraphicsRow, even if (I believe) I properly take into accout image sizes and paddings.
My goal is the following: After I put six identical plots in grid, I would like to add a seventh plot to the right, which has different dimensions and then export everything to .pdf.
I understand that if I want to preserve the dimensions of the plots with GraphicsGrid/GraphicsRow, I have to correctly specify the aspect ratio and ImageSize of all the plots. I define the image sizes of my plots to be the sum of the frame size and image padding, like in the following code:
data = Table[RandomReal[], {10}]; (* Some data to plot *)
(* Defining relevant dimensions for plot 1*)
framex1 = 100;
framey1 = 100;
paddingx1 = {50, 10};
paddingy1 = {50, 10};
imagepadding1 = {paddingx1, paddingy1}
imagesize1 = {framex1 + Total[paddingx1], framey1 + Total[paddingy1]}
plot1 = ListPlot[data, PlotMarkers -> Automatic,
Frame -> True, FrameLabel -> {"foo", "bar"},
AspectRatio -> framey1/framex1, ImageSize -> imagesize1,
ImagePadding -> imagepadding1]
This code produces this plot:
Then I put six copies of this plot in a grid:
gridplot =
GraphicsGrid[{{plot1, plot1, plot1}, {plot1, plot1, plot1}},
Spacings -> 0, ImageSize -> {3 imagesize1[[1]], 2 imagesize1[[2]]}]
This works fine. In this case gridplot actually shows 6 identical copies of plot1, with the correct size. The result is:
Now I consider the additional plot. I am careful to set the vertical size to be equal to the one of gridplot, setting the vertical padding accordingly:
(* Defining relevant dimensions for plot 2*)
framex2 = 100;
framey2 = 150;
paddingx2 = {50, 10};
paddingy2 = {(2 imagesize1[[2]] - framey2)/
2, (2 imagesize1[[2]] - framey2)/2};
imagepadding2 = {paddingx2, paddingy2}
imagesize2 = {framex2 + Total[paddingx2], 2 imagesize1[[2]]}
plot2 = ListPlot[data, PlotMarkers -> Automatic,
Frame -> True, FrameLabel -> {"foo", "bar"},
AspectRatio -> framey2/framex2, ImageSize -> imagesize2,
ImagePadding -> imagepadding2]
Now, if I put gridplot and plot2 side-by-side, I see that the dimensions are correct. In particular the list
{gridplot, plot2}
gives:
However, If I now use GraphicsRow the plots are different and the image padding is messed up!
plot = GraphicsRow[{gridplot, plot2}, Spacings -> 0,
ImageSize -> {3 imagesize1[[1]] + imagesize2[[1]],
2 imagesize1[[2]]}]
What am I getting wrong? I have the feeling it might have to do with ImagePadding passed to GraphicsRow/GraphicsGrid.
One solution would be to rasterize the images before using GraphicsRow/GraphicsGrid, but this would prevent to export the final result in vectorial form.
Any help would be appreciated!