Wolfram mathematica Wolfram Mathematica:y轴框架标签未对齐
我正在用Mathematica制作一个双面板图形。底部面板在y轴上具有负值,这会导致该轴上使用FrameLabel生成的标签比顶部面板上具有正值的标签更向左对齐。我无法将面板连接到单个绘图,因为比例不同。 再现问题的一段代码:Wolfram mathematica Wolfram Mathematica:y轴框架标签未对齐,wolfram-mathematica,plot,text-alignment,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 -&
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标签在顶部和底部面板中对齐。
我将感谢任何帮助-我必须提交的数字(显然没有上述数字…)出版商尽快为我的论文去打印。。。
谢谢您可以在第一个绘图中使用
FrameTicks
在标签y
和勾选标签之间留出一些空间,如下所示:
关键技巧是使用足够的填充设置一个自定义标签(例如,标签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]}]
提供以下输出:
以下是一些想法。首先是:
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];
您可以使用标签为的:
labelIt =
Labeled[#, Style[#2, 25, Bold, FontFamily -> Times], Left, RotateLabel -> True] &;
Column[{labelIt[p1, "y"], labelIt[p2, "y"]}]
或者将标签放在单独的网格中
单元格:
{lab1, lab2} =
Rotate[Style[#, 25, Bold, FontFamily -> Times], Pi/2] & /@ {"y", "y"};
Grid[{{lab1, p1}, {lab2, p2}}, Spacings -> 0]
我通过使用插图替换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]
}
]
这将产生以下结果:
我看到了其他的解决方案-谢谢你们,但我更喜欢我的解决方案,尽管它与@Mr.Wizard solution非常相似。很抱歉刚刚发布了解决方案,但当我找到它时,我无法发布,因为网站要求我等待8小时才能回答我自己的问题。我通过使用插图而不是框架标签解决了问题,插图可以指定方向,以便旋转。我想发布一个完整的答案,但没有足够的声誉来回答我自己的问题。。。请参阅,不要忘记设置PlotRangeClipping->False
,这样放置在绘图区域之外的插图就不会被剪裁和隐藏。如果没有其他选项,您可以编辑问题以附加解决方案。我觉得这是很有价值的。你以9秒的速度第一个发帖。:-)关于你的方法,我真的不喜欢改变滴答声的想法。我的方法当然也不完美。@Wizard先生,如果我知道我会等9秒:)因为我更喜欢你的方法,只是投了赞成票。但是OP似乎处于恐慌之中,考虑到MMA SE站点之后这里的流量减少,我认为任何有效的都是可以接受的。谢谢投票。如果你注意到我们两人都被打败了:请看问题下方的评论。@Mr.Wizard,直到两件事:如何通过将鼠标悬停在x小时/天之前
,获得第二篇帖子的准确时间戳,以及TIL的含义(通过另一篇SE帖子)。感谢您发布此帖子。如果你更喜欢你的方法,你应该接受你自己的答案。您可能需要等待两天才能完成此操作。