将图形另存为“eps”文件时不显示Matplotlib中文字符

2024-05-17 07:49:52 发布

您现在位置:Python中文网/ 问答频道 /正文

问题被描述为标题。你知道吗

例如:

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
mpl.rcParams['font.sans-serif'] = ['SimHei']

plt.figure()
plt.title('哈哈')
plt.savefig('try.png')
plt.savefig('try.eps')

然后,结果是:

你知道吗试用.png:

enter image description here

你知道吗试用.eps:

enter image description here

保存方法可以很好地处理“png”、“jpg”,但不能在“eps”中呈现汉字。此外,你可以发现数字的字体在eps绘图也看起来很奇怪。你知道吗


Tags: import标题pngmatplotlibuseasplteps