matplotlib和Latex使用问题
问题描述
plt.show无法显示图中的Latex公式,只显示了字符串。但plt.savefig后,打开保存的图片中可以正确显示图中的Latex公式。第一幅图中是show的,第二幅图中是打开save后的文件。
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/f3f22adf27d24309b05ef30099c1568b.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/785d6c684926428483310302b85dc931.png)
解决方案
在import matplotlib.pyplot as plt语句前,加上一句话:
import matplotlib as mpl
mpl.use(‘TkAgg’)
这样show就可以正常显示了
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/bb95d550055b4b7eab4dd26117c20068.png)
参考
https://www.jianshu.com/p/2b38f07375f1