from pylab import *
import random
import matplotlib  as mpl
import matplotlib .pyplot as plt
import numpy as np

myfont = matplotlib.font_manager.FontProperties(fname=r"simkai.ttf")  #fname指定字体文件  选简体显示中文
#第七行的作用是为了消除更换为unicode字体之后0、负数之类的显示异常。之后所有使用中文字体的地方只字符串都以u""的形式出现,并指定fontproperties属性为我们的指定的myfont就行了
mpl.rcParams['axes.unicode_minus'] = False
mpl.rcParams['font.sans-serif'] = ['SimHei']
t = np.arange(-5*np.pi, 5*np.pi, 0.001)
y = np.sin(t)/t
my_post = plt.plot(t, y)
plt.title(u'matplotlib中文显示测试——Tacey Wong',fontproperties=myfont)
plt.xlabel(u'这里是X坐标',fontproperties=myfont)
plt.ylabel(u'这里是Y坐标',fontproperties=myfont)

plt.show()

matplotlib中文显示问题

相关文章:

  • 2021-07-07
  • 2021-05-23
  • 2021-10-25
  • 2021-12-15
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-10
  • 2021-12-06
  • 2022-12-23
  • 2021-06-23
  • 2021-11-20
相关资源
相似解决方案