以 eps 格式导出时,Matplotlib 标签/标题消失 [英] Matplotlib labels/titles disappear when exporting in eps format
问题描述
我试图以eps格式保存matplotlib图形,但是当我使用savefig()时,标签和标题都消失了.它适用于所有其他类型的输出,所以我不确定出了什么问题.
I'm trying to save a matplotlib figure in eps format, but when I use savefig(), the labels and titles all disappear. It works fine with every other type of output, so I'm not sure what's going wrong.
import numpy as np
import matplotlib.pyplot as plt
data = np.random.rand(4,4)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(data)
plt.title('Title')
plt.xlabel('x axis')
plt.ylabel('y axis')
fig.savefig('test.eps')
fig.savefig('test.png')
我从中获得的 .png 文件已正确标记(plt.show() 看起来也不错),但 .eps 最终没有标签.有什么想法吗?(我仍在学习如何使用 matplotlib,所以这可能是我忽略的一个简单的解决方法......)
The .png file I get from this is properly labeled (plt.show() also looks okay), but the .eps ends up without labels. Any thoughts? (I'm still learning how to use matplotlib, so it might be an easy fix that I'm overlooking...)
推荐答案
您使用的后端不支持您使用的字体包.
The backend you are using isn't supporting the font package you're using.
尝试将 matplotlib 后端设置为已知后端之一.这必须在导入 matplotlib 之前完成.
Try setting the matplotlib backend to one of the known backends. This must be done before you import matplotlib.
要了解当前设置了哪个后端,请参阅matplotlib.get_backend().
To find out which backend is currently set, see matplotlib.get_backend().
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
这篇关于以 eps 格式导出时,Matplotlib 标签/标题消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!