简体   繁体   English

带有Python 3.7和Matplotlib的LaTeX

[英]LaTeX with Python 3.7 and Matplotlib

I just installed Python 3.7.1 and ran the following script: 我刚刚安装了Python 3.7.1,并运行了以下脚本:

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots(); frame = plt.gca()
x = np.linspace(0,2*np.pi,500)
y = np.sin(x)
ax.set_xticks(np.array([0,np.pi,2*np.pi]))
ax.set_yticks(np.array([-1,0,1]))
frame.set_xticklabels(['$0$', '$\pi$', '$2\pi$'], fontsize=20)
frame.set_yticklabels(['$-1$', '$0$', '$1$'], fontsize=20)
ax.plot(x, y)
plt.tight_layout()
plt.show()

Back in Python 2.7, the x and y tick labels would show up in LaTeX form as I wanted. 回到Python 2.7,x和y刻度标签将按照我的需要以LaTeX形式显示。 Now they default to a much less pretty font, and I can't figure out how to show them in LaTeX font. 现在它们默认使用的字体要漂亮得多,而且我不知道如何用LaTeX字体显示它们。 Do I need to install an newer version of matplotlib? 我需要安装较新版本的matplotlib吗?

Thanks to tmdavison's link I was able to figure it out. 多亏了tmdavison的链接,我才能够弄清楚它。 All I need to do is add the following lines of code: 我需要做的就是添加以下代码行:

import matplotlib as mpl
mpl.style.use('classic')

Then Matplotlib will default back to the classic style. 然后Matplotlib将默认恢复为经典样式。

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

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