原文地址:http://blog.csdn.net/rumswell/article/details/6544377

#Matplotlib中文显示有问题,当然可以修改配置文件matplotlibrc ,不过较为麻烦.其实只要在代码中指定字体就可以了

#第一种方法:

# -*- coding: utf-8 -*-
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei'] #指定默认字体

mpl.rcParams['axes.unicode_minus'] = False #解决保存图像是负号'-'显示为方块的问题

t = arange(-5*pi, 5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文')
plt.xlabel(u'X坐标')
plt.ylabel(u'Y坐标')
plt.show()

 

 

#第二种方法

# -*- coding: utf-8 -*-
from pylab import *
myfont = matplotlib.font_manager.FontProperties(fname='C:/Windows/Fonts/msyh.ttf')
mpl.rcParams['axes.unicode_minus'] = False
t = arange(-5*pi, 5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文',fontproperties=myfont) #指定字体
plt.xlabel(u'X坐标',fontproperties=myfont)
plt.ylabel(u'Y坐标',fontproperties=myfont)
plt.show()

 

相关文章:

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