1
$\begingroup$

I want to use GraphicsColumn[] to stack two images that have the same width but not the same height. As stated in the documentation for that function:

GraphicsColumn will by default make all items the same height, preserving individual aspect ratios for graphics, and leaving space if necessary.

This would seem to suggest that there's something I can do to have it respect the differing heights, thus allowing the widths to equate. But I can't find any explicit instructions on how to do so in the documentation. Any ideas?

$\endgroup$
3
$\begingroup$

To have plots with the same width in a GraphicsColumn, they need to use the same ImagePadding and ImageSize specs. For example:

GraphicsColumn[{
    Plot[Sin[x], {x, 0, 1}, ImagePadding->30, ImageSize->300],
    Plot[x^2, {x, 0, 100}, ImagePadding->30, ImageSize->300]
}]

enter image description here

However, suppose you don't know the ImagePadding? In this case you can make use of my graphicsInformation function from question 2091. For example, here are the two plots using the default ImagePadding:

p1 = Plot[Sin[x], {x, 0, 1}, ImageSize->300];
p2 = Plot[x^2, {x, 0, 100}, ImageSize->300];

graphicsInformation[p1]
graphicsInformation[p2]

{"ImagePadding" -> {{11.2708, 2.27083}, {8.14795, 0.5}}, "ImageSize" -> {300., 185.689}, "PlotRangeSize" -> {286.458, 177.041}, "ImagePaddingSize" -> {13.5417, 8.64795}, "PlotRange" -> {{-0.0208333, 1.02083}, {-0.0467484, 0.888219}}}

{"ImagePadding" -> {{26.6146, 4.11458}, {8.67907, 0.5}}, "ImageSize" -> {300., 175.598}, "PlotRangeSize" -> {269.271, 166.419}, "ImagePaddingSize" -> {30.7292, 9.17907}, "PlotRange" -> {{-2.08333, 102.083}, {-555.556, 10555.6}}}

We see that the second plot has a larger horizontal padding. So, the simplest thing to do is to use this padding for both plots:

padding = "ImagePadding" /. graphicsInformation[p2];
GraphicsColumn[{
    Show[p1, ImagePadding->padding],
    Show[p2, ImagePadding->padding]
}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for this information! My two images actually have the same width and padding, but its distorts the widths in trying to equate their different heights. Your answer does suggest a workaround in which I put enough padding below the shorter image to equate each image's height+vertical padding. And I can probably even crop the result to remove the padding. If nobody proposes a more elegant solution in the next few days, I'll accept this as it does help me get where I need to go with the figure, even if it's a bit indirect. Again: thanks! $\endgroup$ – Shane Jun 21 '17 at 11:52
  • $\begingroup$ @Shane Providing your images would be useful if you wanted a more targeted answer. $\endgroup$ – Carl Woll Jun 22 '17 at 0:16

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.