Aligning ListPlots

Aligning ListPlots

Post by Jan Rychte » Tue, 05 Jun 2007 16:48:49

I always thought it to be a big omission in Mathematica that there was
no facility for easily aligning multiple plots in a grid or column. Now,
with the arrival of Mathematica 6, we finally have GraphicsGrid,
GraphicsColumn and GraphicsRow!

But -- I find those are essentially useless. When I build a
GraphicsColumn composed of multiple ListPlots, the vertical axes are NOT
aligned. Instead, Mathematica chooses to align the text labels on the
axes. Because of this, examples in the manual look just fine, because
labels on all the graphs are of the same length. But if you have, say,
two ListPlots, and one has labels in the range 1..5 and the other in the
range 10,000..100,000, the vertical axes will not align and the whole
column will look bad.

Does anyone know of a solution to this?


Aligning ListPlots

Post by Carl Wol » Wed, 06 Jun 2007 19:43:31

Look up ImagePadding in the help:


ImagePadding is an option for graphics functions that specifies what \
absolute extra padding should be left for extended objects such as \
thick lines and annotations such as tick and axis labels.

Here are two examples:

padding = {{80, 10}, {30, 10}};

GraphicsGrid[{{Plot[x^2, {x, 0, 5}, ImagePadding -> padding]}, {Plot[
100000 x^2, {x, 0, 5}, ImagePadding -> padding]}}]

GraphicsColumn[{Plot[x^2, {x, 0, 5}], Plot[100000 x^2, {x, 0, 5}]} /.
Graphics[a_, b_List] :> Graphics[a, Append[b, ImagePadding -> padding]]]

Carl Woll
Wolfram Research


Aligning ListPlots

Post by Hugh » Wed, 06 Jun 2007 19:59:52

I found one solution in V6 which I posted in May at

and discussed various plots and one trick. Please look at this post.

The difficulty with formatting multiple plots is that the space for
numbers and text
must be given in the text units of points (with 72 points per inch)
while the
coordinates making up the plot use their own coordinate units.

Below is a solution for ListPlot

Hugh Goyder

d1 = Table[{x, Sin[x]}, {x, 0, 5*Pi, Pi/10}];

d2 = Table[{x, 10^5*Cos[x]}, {x, 0, 5*Pi, Pi/10}];

Graphics[{Inset[ListPlot[d1, PlotRange -> {{0, 5*Pi}, {-1, 1}},
PlotRangePadding -> {None, None},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12},
Frame -> True, Axes -> False,
FrameLabel -> {None, "Amplitude 1"}, AspectRatio -> 2/5,
ImagePadding -> {{72, 1}, {24, 12}}], {0,
2.3333*72}, {0, -1}, 6*72],
Inset[ListPlot[d2, PlotRange -> {{0, 5*Pi}, {-10^5, 10^5}},
PlotRangePadding -> {None, None},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12},
Frame -> True, Axes -> False,
FrameLabel -> {"Time", "Amplitude 2"}, AspectRatio -> 2/5,
ImagePadding -> {{72, 1}, {48, 12}}], {0, 0}, {0, -10^5},
PlotRange -> {{0, 5*72}, {0, 4.3333*72}}, AspectRatio -> 4.3333/5,
ImageSize -> 6*72,
ImagePadding -> {{72, 1}, {48, 12}}]

Aligning ListPlots

Post by Lev Bisho » Thu, 07 Jun 2007 19:42:04


Use the ImagePadding option to the Plot family of functions,

Aligning ListPlots

Post by Jan Rychte » Thu, 14 Jun 2007 20:58:00

I'd like to thank everyone for the helpful answers. I will be working on
creating my own function that aligns my ListPlots properly.

However, I find one thing very puzzling: why in the world do we have to
do this kind of thing manually ourselves? Or, in other words, how is the
current behavior of aligning plots in GraphicsGrids useful to anyone?

I find it hard to imagine a scenario where you would not want your axes
to be perfectly aligned.