matplotlib.pyplot的plt绘图不显示中文

(1)在python安装目录的Lib目录下创建ch.py文件

#-*-coding:utf-8-*-  

def set_ch():  
    from pylab import mpl  
    mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体  
    mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题  

(2)测试

#-*-coding:utf-8-*-  

import ch  
ch.set_ch() 
from matplotlib import pyplot as plt
plt.title(u'显示中文')
plt.show()

(3)字体选择 

转载地址:https://blog.csdn.net/qingchunlizhi/article/details/59481608 

发布了348 篇原创文章 · 获赞 210 · 访问量 87万+

猜你喜欢

转载自blog.csdn.net/u010916338/article/details/96430916
今日推荐