# GraphicsGrid of plots with legends

I use GraphicsGrid to get a table of contour plots, where each of the plots is using its own scaling, so I want to include the bar legend for each of the plots. But if I do this, GraphicsGrid seems to ignore the place needed for the legend when calculating the grid item size, and the plots are scaled larger then grid cells.

MWE:

GraphicsGrid@
Table[ContourPlot[ Cos[x]/k + Cos[ m y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ColorFunction -> "Rainbow", PlotLegends -> Automatic], {k, 1,
2}, {m, 1, 2}]


Is there any better way to fix it rather then to set fixed plot size and to tune manually the ItemAspectRatio, like below?

GraphicsGrid[
Table[ContourPlot[ Cos[x]/k + Cos[ m y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ColorFunction -> "Rainbow", PlotLegends -> Automatic,
ImageSize -> 100], {k, 1, 2}, {m, 1, 2}], ItemAspectRatio -> .6]


• This is a known bug. I have added the tag 'bugs'. – m_goldberg Sep 8 '17 at 17:48
• Related; maybe a dupe. – corey979 Apr 13 '19 at 13:36

It's a bug. I had a similar problem with GraphicsGrid, reported it, and received a reply from WRI tech support. I quote the relevant portion.

When you put the plots inside a GraphicsGrid, they are put inside individual insets. Unfortunately, there is a known issue with GraphicsGrid failing to determine the optimal size for graphics with insets.

So, I recommend you to avoid using plots along the GraphicsGrid.

Try Grid instead.

Grid @
Table[
ContourPlot[Cos[x]/k + Cos[m y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ColorFunction -> "Rainbow", PlotLegends -> Automatic],
{k, 1, 2}, {m, 1, 2}]


• Thanks a lot! I would still prefer to use manual tuning because of not uniform heights of the bar legends with Grid method. – Oleg Soloviev Sep 8 '17 at 20:40

One option is to rasterize the plots before using GraphicsGrid

GraphicsGrid[
Table[Rasterize[
ContourPlot[Cos[x]/k + Cos[m y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ColorFunction -> "Rainbow", PlotLegends -> Automatic,
ImageSize -> 300]], {k, 1, 2}, {m, 1, 2}]]


this will produce