7
$\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$
  • $\begingroup$ This is a known bug. I have added the tag 'bugs'. $\endgroup$ – m_goldberg Sep 8 '17 at 17:48
  • $\begingroup$ Related; maybe a dupe. $\endgroup$ – corey979 Apr 13 at 13:36
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$
  • $\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$ – Oleg Soloviev Sep 8 '17 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$

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.