python matplotlib画图改为可写中文

1. 安装好 matplotlib 包
2. 把  Microsoft Yahei Bold.ttf  微软雅黑字体文件放到  /usr/local/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf  这个目录下
3. 把 /usr/local/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc    这个文件修改
195行   font.family         : sans-serif    取消注释
大约207行  添加红色字内容
font.sans-serif     : Microsoft Yahei,DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana,.....

或者可以在本地改好,替换掉需要修改的文件 ,这样可以避免安装vim 和跟新新apt  update ,使打出来的镜像变大

4. 测试

python  demo.py   查看图片标题是否为中文

import matplotlib.pyplot as plt


plt.title(u"中文标题")
plt.savefig("chinese_test.png")

 

posted on 2020-06-08 10:49  闹不机米  阅读(431)  评论(0编辑  收藏  举报

导航