简体   繁体   English

乳胶与matplotlib,轴标签不正确

[英]Latex with matplotlib, axis label not correct

I'm trying to use matplotlib for creating plots and use them inside my latex document. 我正在尝试使用matplotlib创建绘图并在我的乳胶文档中使用它们。 Actually it works quite good to use latex-style fonts inside the plots, but for some reason the first label of each axis has another layout then the other labels, it seems to be thicker. 实际上,在绘图中使用乳胶风格的字体非常有效,但由于某种原因,每个轴的第一个标签有另一个布局,然后是其他标签,它看起来更厚。 This is may code 这可能是代码

f, ax = plt.subplots(1,1,figsize=(10,8))
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
suptitle = plt.suptitle("Test plot", y=1.02, size=13)
ax.plot(dummydata1)
ax.plot(dummydata2)
plt.tight_layout()
plt.legend()
plt.savefig("test.pdf", bbox_extra_artist(suptitle,), bbox_inches="tight")

When I open the saved image it looks like this. 当我打开保存的图像时,它看起来像这样。 (zoomed in) You can see that the 0.0 and the 0.05 are different. (放大)你可以看到0.00.05是不同的。

在此输入图像描述

Does anybody knows what could be the solution for this? 有谁知道这可能是什么解决方案?

Make sure to set rcParameters which apply to the axes before creating the axes. 确保创建轴之前设置适用于轴的rcParameters。 Ie instead of 即代替

f, ax = plt.subplots(1,1,figsize=(10,8))
plt.rc('text', usetex=True)
plt.rc('font', family='serif')

use 采用

plt.rc('text', usetex=True)
plt.rc('font', family='serif')

f, ax = plt.subplots(1,1,figsize=(10,8))

Explanation: If you you create the axes, one "master" ticklabel is created. 说明:如果创建轴,则会创建一个“主”勾选标签。 This will have the normal default font settings applied to it. 这将应用正常的默认字体设置。 Then the default font settings are changed. 然后更改默认字体设置。 In consequence they apply to all ticklabels that are created after changing the setting. 因此,它们适用于更改设置后创建的所有ticklabel。 Those are all but the master ticklabel. 这些都是主要的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM