请教作图中的图例设置问题
mathematica吧
全部回复
仅看楼主
level 5
我用show命令画了三条曲线,并且给三条曲线标注了图例。但是发现两个问题:(1)图例之间的间距过大,请问用什么代码可以调整图例之间的间隔?(2)给图例设置字体大小的时候,发现对上标不起作用。比如 y^AB [x] 中 y 和 x 都变成了10号字体,但是上标 AB 的大小却没有改变,请问如何调整上标的字体大小?
我写的代码如下:
Show[Plot[{2^x + 1}, {x, 1, 3}, PlotLegends -> LineLegend[{TraditionalForm[(y^AB)[x]]}, LabelStyle -> 10],
PlotStyle -> Red], Plot[{x + 3}, {x, 1/2, 3}, PlotLegends -> LineLegend[{TraditionalForm[(y^CD)[x]]}, LabelStyle -> 10], PlotStyle -> Blue], Plot[{2 x^2}, {x, 0, 2}, PlotLegends -> LineLegend[{TraditionalForm[(y^EF)[x]]}, LabelStyle -> 10], PlotStyle -> Black], PlotRange -> All, AxesLabel -> {x, y}, AxesOrigin -> {0, 0}]
运行结果如下图:
请高手帮忙看看,谢谢啦!另外我之前的账号(@超级city)不知道咋回事最近天发帖发不出去[泪],没办法只能注册了这个新号来问了[乖]
2022年11月19日 17点11分 1
吧务
level 10
我没这个情况,文字及其上标是一起变的。
2022年11月22日 12点11分 2
level 7
LegendLayout -> (Grid[#, Alignment -> Left, Spacings -> {1, .2}] &)图例间距可以用Spacing调
2022年11月22日 16点11分 3
试了一下,你写的这个命令好像对图例之间的垂直距离不起作用。我发现用“LegendMarkerSize”倒是可以调整图例的垂直间距。
2022年11月23日 14点11分
@sunflower_2023 改里面的数字
2022年11月23日 14点11分
@Yumiko🍁 改了,不起作用。你说的是这样吧:PlotLegends -> LineLegend[{TraditionalForm[(y^AB)[x]]}, LabelStyle -> 10, LegendLayout -> (Grid[#, Alignment -> Left, Spacings -> {1, -5}] &)] 即使把 Spacings 后面的第二项改成 -5,图例的上下间距仍然不变。
2022年11月23日 15点11分
PlotLegends -> LineLegend[{TraditionalForm[(y^AB)[x]]}, LabelStyle -> 10, LegendMargins -> {{-15, 0}, {-3, 0}}]
2024年01月30日 08点01分
level 1
我来说说我对于第一个问题的解决办法(曾经也折磨了我好久)。首先这个方法来自于LegendLayout的帮助文档。这里使用了格式化的表格,代码就可以写成这样:
table[pairs_] :=
TableForm[pairs, TableAlignments -> Left, TableSpacing -> {0, 0.5}]
Plot[{Sin[x], Cos[x]}, {x, 0, 2*Pi},
PlotLegends ->
Placed[LineLegend[{"sin(x)", "cos(x)"}, LegendMargins -> 0,
LegendFunction -> (Framed[#, RoundingRadius -> 5] &),
LegendLayout -> table], {0.65, 0.8}]]
现在就可以通过调节表格间距来调整图例间距了。
这里的pairs就是mark和文字组成的对。可以对它进行一些操作,比如逆序,分组等。
2022年11月26日 07点11分 4
谢谢!我发现用“LegendMarkerSize”可以调整图例的垂直间距。当然应该没你这个代码这么精细。
2022年11月28日 00点11分
吧务
level 15
反正帖子挖上来你们也不看是吧:
tieba.baidu.com/p/7500053469?pid=141153946188&cid=0#141153946188
2022年12月03日 03点12分 5
1