2

I'm producing a double panel figure in Mathematica. The Bottom panel has negative values on the y-axis and this causes the label on that axis, produced using FrameLabel, to be aligned a bit more to the left than the label on the top panel, which has positive values. I cannot join the panels to a single plot because the scales are different. A piece of code that reproduces the problem:

pad = 80;
Export["C:\\Users\\user\\Desktop\\stackoverflow.png",
 Column[
  {
   Show[
    Plot[ Sin[x]^2, {x, 0, Pi},
     FrameLabel -> {"", "y"},
     BaseStyle -> {FontSize -> 16, FontWeight -> Bold, 
       FontFamily -> "Calibri"},
     ImagePadding -> {{pad, pad/4}, {pad, pad/4}},
     Frame -> {True, True, True, True}
     ]
    , ImageSize -> 640]
   ,
   Show[
    Plot[ -Sin[x]^2/1000, {x, 0, Pi},
     FrameLabel -> {"x", "y"},
      BaseStyle -> {FontSize -> 16, FontWeight -> Bold, 
       FontFamily -> "Calibri"},
     ImagePadding -> {{pad, pad/4}, {pad, pad/4}},
     Frame -> {True, True, True, True}
     ]
    , ImageSize -> 640]
   }
  ]
 ]

This code produces the following figure, in which you can see that the y label is aligned differentyl in the top and bottom panels. misaligned y labels

I would appreciate any help - I have to submit the figure (obviously no the above figure...) to the publisher ASAP for my paper to go to print... Thanks

yoavram
  • 4,289
  • 3
  • 21
  • 21
  • I solved the problem by using an Inset instead of the FrameLabel, The Inset can be given a direction so that it will be rotated. I wanted to post a full answer but don't have enough reputation to answer my own question... see [Inset doc](http://reference.wolfram.com/mathematica/ref/Inset.html) and don't forget to set `PlotRangeClipping -> False` so that an inset that is placed outside of the plotting area will not be clipped and hidden. – yoavram Feb 09 '12 at 09:26
  • rocky, you can edit the question to append your solution if no other option is available. I feel that it would be valuable. – Mr.Wizard Feb 09 '12 at 09:47

3 Answers3

2

I solved the problem by replacing the FrameLabel with an Inset:

Column[
 {
  Show[
   Plot[ Sin[x]^2, {x, 0, Pi},
    FrameLabel -> {"", ""},
    Epilog -> {
      Inset["y", ImageScaled[{0.01, 0.55}], {0, 0}, Automatic, {0, 1}]
      },
    BaseStyle -> {FontSize -> 16, FontWeight -> Bold, 
      FontFamily -> "Calibri"},
    ImagePadding -> {{pad, pad/4}, {pad, pad/4}},
    Frame -> {True, True, True, True},
    PlotRangeClipping -> False
    ]
   , ImageSize -> 640]
  ,
  Show[
   Plot[ -Sin[x]^2/1000, {x, 0, Pi},
    FrameLabel -> {"x", ""},
    PlotRangeClipping -> False,
    Epilog -> {
      Inset["y", ImageScaled[{0.01, 0.55}], {0, 0}, Automatic, {0, 1}]
      },
    BaseStyle -> {FontSize -> 16, FontWeight -> Bold, 
      FontFamily -> "Calibri"},
    ImagePadding -> {{pad, pad/4}, {pad, pad/4}},
    Frame -> {True, True, True, True}
    ]
   , ImageSize -> 640]
  }
 ]

Which produces the following: Solution

I saw the other solutions posted - thanks you guys, but I like my solution better, although it's very similar to @Mr.Wizard solution. Sorry for posting the solution just now, but when I found it I couldn't post as the site asked that I wait 8 hours before answering my own question.

yoavram
  • 4,289
  • 3
  • 21
  • 21
  • Thanks for posting this. If you like your method better you should accept your own answer. You will probably have to wait two days to do this. – Mr.Wizard Feb 10 '12 at 12:51
1

Here are a couple of ideas. Starting with:

pad = 80;
options := 
  Sequence[BaseStyle -> {FontSize -> 16, FontWeight -> Bold, FontFamily -> "Calibri"}, 
   ImagePadding -> {{pad, pad/4}, {pad, pad/4}}, Frame -> True, 
   ImageSize -> 649];

p1 = Plot[Sin[x]^2, {x, 0, Pi}, Evaluate@options];

p2 = Plot[-Sin[x]^2/1000, {x, 0, Pi}, 
   FrameLabel -> Style["x", 25, Bold, FontFamily -> Times], Evaluate@options];

You could use Labeled:

labelIt = 
  Labeled[#, Style[#2, 25, Bold, FontFamily -> Times], Left, RotateLabel -> True] &;

Column[{labelIt[p1, "y"], labelIt[p2, "y"]}]

Or put the labels in a separate Grid cell:

{lab1, lab2} =
  Rotate[Style[#, 25, Bold, FontFamily -> Times], Pi/2] & /@ {"y", "y"};

Grid[{{lab1, p1}, {lab2, p2}}, Spacings -> 0]
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
0

You can use FrameTicks in the first plot to make some space between the label y and ticklabels as follows:'

The key trick is to have one of your custom labels (say, label 0.0) styled with enough padding:

  frmticks1 = {{{{0.0, "         0.0"}, {0.2, "0.2"}, {0.4, 
  "0.4"}, {0.6, "0.6"}, {0.8, "0.8"}, {1.0, "1.0"}}, 
  Automatic}, {Automatic, Automatic}};

Then, adding the option FrameTicks->frmticks1 to the first plot:

  Column[{Show[
  Plot[Sin[x]^2, {x, 0, Pi}, FrameLabel -> {"", "y"}, 
   BaseStyle -> {FontSize -> 16, FontWeight -> Bold, 
  FontFamily -> "Calibri"}, 
  ImagePadding -> {{pad, pad/4}, {pad, pad/4}}, 
  Frame -> {True, True, True, True}, FrameTicks -> frmticks1], 
  ImageSize -> 640], 
   Show[Plot[-Sin[x]^2/1000, {x, 0, Pi}, FrameLabel -> {"x", "y"}, 
  BaseStyle -> {FontSize -> 16, FontWeight -> Bold, 
  FontFamily -> "Calibri"}, 
  ImagePadding -> {{pad, pad/4}, {pad, pad/4}}, 
  Frame -> {True, True, True, True}], ImageSize -> 640]}]

gives the following output:

enter image description here

kglr
  • 1,438
  • 1
  • 9
  • 15
  • You posted first by literally *nine seconds*. :-) – Mr.Wizard Feb 09 '12 at 09:29
  • Regarding your method I don't really like the idea of having to change Ticks. Mine is certainly not perfect either. – Mr.Wizard Feb 09 '12 at 09:31
  • @Mr.Wizard, if I had known I would have waited 9 seconds:) because I like your method better and just voted for it. But the OP seemed to be in panic and given the reduced traffic here after MMA SE site, I thought anything that worked would be acceptable. – kglr Feb 09 '12 at 09:36
  • Thanks for the vote. If you notice the OP beat both of us: look at the comment below the question. – Mr.Wizard Feb 09 '12 at 09:45
  • 1
    @Mr.Wizard, TIL two things: how to get the exact timestamp to the second of posts by hovering over `x hours/days ago`, and what TIL means (thru another SE post). – kglr Feb 09 '12 at 09:56