8
$\begingroup$

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}] 

oversized items in GrpahicsGrid

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] 

enter image description here

$\endgroup$
2
  • $\begingroup$ This is a known bug. I have added the tag 'bugs'. $\endgroup$ Commented Sep 8, 2017 at 17:48
  • $\begingroup$ Related; maybe a dupe. $\endgroup$ Commented Apr 13, 2019 at 13:36

2 Answers 2

3
$\begingroup$

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}] 

grid

$\endgroup$
1
  • $\begingroup$ Thanks a lot! I would still prefer to use manual tuning because of not uniform heights of the bar legends with Grid method. $\endgroup$ Commented Sep 8, 2017 at 20:40
1
$\begingroup$

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 enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.