3
$\begingroup$

I am having trouble combining images using GraphicsGrid. My question is similar to Too much whitespace in a GraphicsGrid containing Legended Plots but it seems more complicated because I want to have one image centered above two other images for which I use SpanFromLeft (perhaps not the right tool?).

Can anyone explain how I should pick the image sizes and aspect ratios so that they are roughly the same for every individual plot and with as little white space between the plots as possible.

The closest I could get was:

imageSize = 600;
GraphicsGrid[{{ListPlot[RandomReal[{0, 1}, {10, 2}], 
    ImageSize -> imageSize*Sqrt[2], AspectRatio -> 1/GoldenRatio], 
   SpanFromLeft}, {ListPlot[RandomReal[{0, 1}, {10, 2}], 
    ImageSize -> imageSize, AspectRatio -> 1/GoldenRatio], 
   ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize, 
    AspectRatio -> 1/GoldenRatio]}}, ImageSize -> 1000
 , AspectRatio -> 1/GoldenRatio
 ]

I have no idea why I would need to multiply by Sqrt[2] in the top plot to get a similarly sized image as the others. It probably has to do with me combining two cells using SpanFromLeft.

$\endgroup$
4
  • $\begingroup$ There are many questions on this site about PlotGrid which could be what you want. $\endgroup$
    – Syed
    Apr 28 at 13:36
  • $\begingroup$ Hmm perhaps. If Built-in functions can do what I want I would prefer that. But perhaps PlotGrid is the better tool. I don't know. $\endgroup$
    – Kvothe
    Apr 28 at 13:38
  • 3
    $\begingroup$ Do you really need GraphicsGrid? If you simply use Grid, it works perfectly as expected: imageSize = 300; Grid[{{ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize], SpanFromLeft}, {ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize], ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize]}}] $\endgroup$
    – Domen
    Apr 28 at 13:42
  • $\begingroup$ @Domen, right it has been suggested before that GraphicsGrid might just be a bad function and we should use Grid as an alternative. GraphicsGrid seems intuitively closer to what I want though. I would prefer an image that I can rescale with ImageSize. I also don't know whether Grid would export correctly as one image (perhaps it does I never tried or looked into it). $\endgroup$
    – Kvothe
    Apr 28 at 13:47

2 Answers 2

7
$\begingroup$

Seems you can just leave away the ImageSize specifications:

GraphicsGrid[
 {
  {
   ListPlot[RandomReal[{0, 1}, {10, 2}], Frame -> True],
   SpanFromLeft
   }, {
   ListPlot[RandomReal[{0, 1}, {10, 2}], Frame -> True], 
   ListPlot[RandomReal[{0, 1}, {10, 2}], Frame -> True]
   }
  },
 ImageSize -> 600, AspectRatio -> 1/GoldenRatio, Spacings -> 0
 ]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks! Indeed that works. Do you understand why it works? Is it because the default ImageSize is somehow the correct one to combine at this AspectRatio or is it because not specifying leaves MMA more free to pick it a the end? $\endgroup$
    – Kvothe
    Apr 28 at 13:44
  • 1
    $\begingroup$ AspectRatio -> 1/GoldenRatio is default setting btw $\endgroup$ Apr 28 at 14:08
  • $\begingroup$ @Kvothe Unfortunately, I don't know how exactly GraphicsGrid decides on the size of things.. $\endgroup$
    – Lukas Lang
    Apr 28 at 14:44
2
$\begingroup$

Here is a hack that works with arbitrary ImageSize:

imageSize = 300;
Column[{
  Row[{Graphics@Text[""], 
    ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize, 
     AspectRatio -> 1/GoldenRatio], Graphics@Text[""]}, 
   StringRepeat[" ", Round[imageSize/12]]], 
  Row[{ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize, 
     AspectRatio -> 1/GoldenRatio], 
    ListPlot[RandomReal[{0, 1}, {10, 2}], ImageSize -> imageSize, 
     AspectRatio -> 1/GoldenRatio]}]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.