Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

Suppose that I have two plots (e.g., Plot, ListPlot, etc) that cover two regions of space. I would like to display them "stacked" vertically, so that they align nicely in publication-quality form.

Suppose that I am dealing with ListPlot and I have the following data:

xdata = Range[0, 2 Pi, 0.2];
ydata1 = Sin[xdata];
ydata2 = 1 + Sin[xdata];

So for plot1, I will plot Transpose[{xdata, ydata1}]; for plot2, I will plot Transpose[{xdata, ydata2}] (both using ListPlot). Plot1 covers both negative and positive $y$ values, whereas plot2 covers only positive $y$ values; this fact will be important later. For both plots, I will use BaseStyle -> {18, FontFamily -> "Arial"} so that the labels are large and legible. I will also use Frame -> True and will include frame labels with FrameLabel -> {"x (Meter)", "y (Meter)"}.

Now if I do the following...

plot1 = ListPlot[Transpose[{xdata, ydata1}], Frame -> True, 
  FrameLabel -> {"x (Meter)", "y (Meter)"}, 
  BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Red, ImageSize -> 375]

plot2 = ListPlot[Transpose[{xdata, ydata2}], Frame -> True, 
  FrameLabel -> {"x (Meter)", "y (Meter)"}, 
  BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Blue, ImageSize -> 375]

...I get the following...

Image1

Notice that above, the frames are not aligned. To fix this, I can specify the same ImagePadding for both plots...

plot1 = ListPlot[Transpose[{xdata, ydata1}], Frame -> True, 
  FrameLabel -> {"x (Meter)", "y (Meter)"}, 
  BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Red, ImageSize -> 375,
  ImagePadding -> {{70, 10}, {55, 10}}]

plot2 = ListPlot[Transpose[{xdata, ydata2}], Frame -> True, 
  FrameLabel -> {"x (Meter)", "y (Meter)"}, 
  BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Blue, ImageSize -> 375,
  ImagePadding -> {{70, 10}, {55, 10}}]

...which gives me the following output...

Image2

Now the frames are nicely aligned. However, the $y$ axis frame labels are not aligned. This is because plot1 includes negative $y$ values in addition to positive ones, and the negative signs "push away" the $y$ axis frame label (i.e., "y (Meter)") in plot1.

So, my question is: is it possible to somehow align the $y$ axis frame labels? Apparently, ImagePadding does not do the trick for that particular issue. Thanks for your time.

share|improve this question
    
This is hardly noticeable ... Could you put y-label on the right perhaps? FrameLabel -> {"x (Meter)", None, None, "y (Meter)"} –  BoLe Oct 12 '13 at 18:09
1  
Bad trick #2: FrameTicks -> {Automatic, {{.5, "+\[VeryThinSpace]0.5"}}}. –  BoLe Oct 12 '13 at 18:12
add comment

marked as duplicate by Ajasja, Sjoerd C. de Vries, Artes, rm -rf Oct 12 '13 at 19:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 4 down vote accepted

You could use Labeled to label the frame. Then the ImagePadding trick will work.

xdata = Range[0, 2 Pi, 0.2];
ydata1 = Sin[xdata];
ydata2 = 1 + Sin[xdata];
imsize = 375;
impad = {{40, 10}, {25, 10}};

plot1 = Labeled[
  ListPlot[Transpose[{xdata, ydata1}], Frame -> True, 
   BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Red, 
   ImageSize -> imsize, ImagePadding -> impad],
  {"x (Meter)", "y (Meter)"}, {Bottom, Left}, RotateLabel -> True, 
  LabelStyle -> {18, FontFamily -> "Arial"}
  ]

plot2 =
 Labeled[
  ListPlot[Transpose[{xdata, ydata2}], Frame -> True, 
   PlotStyle -> Blue, BaseStyle -> {18, FontFamily -> "Arial"}, 
   ImageSize -> imsize, ImagePadding -> impad],
  {"x (Meter)", "y (Meter)"}, {Bottom, Left}, RotateLabel -> True, 
  LabelStyle -> {18, FontFamily -> "Arial"}
  ]

Mathematica graphics

share|improve this answer
add comment

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