在window下 matplotlib 图表显示的是没有问题的。
画图时加上下面一句就能防止乱码。
# 设置中文显示,否则出现乱码!
plt.rc('font', family='SimHei', size=12)
但上传到linux上就中文全显示成口字了。
解决方案;
1.下载simhei.ttf放入你的python环境下的matplotlib的ttf路径下,我这边路径如下:
/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf
2.打开matplotlib/mpl-data/matplotlibrc这个文件
找到font.sans-serif,打开他,然后字前面加上SimHei,加在最前面。
font.sans-serif : SimHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif, Microsoft YaHei
其他的都不需要修改了。
SimHei下载地址:https://www.fontpalace.com/font-download/SimHei/
也可以自己百度搜索下载。