matplotlib的缺省配置文件中所使用的字体无法正确显示中文

matplotlib的缺省配置文件中所使用的字体无法正确显示中文。为了让图表能正确显示中文,可以有几种解决方案。

1、在程序中直接指定字体。

2、在程序开头修改配置字典rcParams。

3、修改配置文件。

from pylab import *
import matplotlib.pyplot as plt

mpl.rcParams['font.sans-serif'] = ['SimHei'] #指定默认字体
mpl.rcParams['axes.unicode_minus'] = False #解决保存图像是负号'-'显示为方块的问题
squares=[0,1,4,9,16,25,30]


#设置图标标题,并给坐标轴加上标签
plt.title("趋势图",fontsize=24)
plt.xlabel("点位",fontsize=14)
plt.ylabel("测量值",fontsize=14)
plt.plot(squares,linewidth=3) #绘制曲线,指定线宽
plt.show()

 

posted @ 2019-07-09 15:56  木公_sdqc518  阅读(261)  评论(0编辑  收藏  举报