Wolfram Mathematica:y轴框架标签未对齐

时间:2012-02-09 08:35:18

标签: wolfram-mathematica plot text-alignment

我在Mathematica中制作了一个双面板图。底部面板在y轴上具有负值,这导致使用FrameLabel生成的该轴上的标签比顶部面板上的标签更左侧对齐,该标签具有正值。我无法将面板连接到单个绘图,因为刻度不同。 一段代码可以重现问题:

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]
   }
  ]
 ]

此代码生成下图,您可以在其中看到y标签在顶部和底部面板中对齐。 misaligned y labels

我将不胜感激任何帮助 - 我必须尽快向出版商提交图片(显然没有上图...),以便我的论文去打印... 感谢

3 个答案:

答案 0 :(得分:2)

我通过使用Inset替换FrameLabel来解决问题:

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]
  }
 ]

产生以下内容: Solution

我看到其他解决方案发布了 - 谢谢你们,但我更喜欢我的解决方案,尽管它与@ Mr.Wizard解决方案非常相似。很抱歉刚刚发布解决方案,但是当我发现它时,我无法发布,因为网站要求我等待8个小时才能回答我自己的问题。

答案 1 :(得分:1)

以下是一些想法。从:

开始
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];

您可以使用Labeled

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

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

或者将标签放在单独的Grid单元格中:

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

Grid[{{lab1, p1}, {lab2, p2}}, Spacings -> 0]

答案 2 :(得分:0)

您可以在第一个图中使用FrameTicks在标签y和ticklabels之间留出一些空格,如下所示:'

关键技巧是让你的一个自定义标签(比方说,标签0.0)用足够的填充样式设置:

  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}};

然后,将选项FrameTicks->frmticks1添加到第一个图:

  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]}]

给出以下输出:

enter image description here