Python matplotlib中文显示异常,导入simhei字体有误
查找matplotlib字体安装路径import matplotlibprint(matplotlib.matplotlib_fname())下载simhei.tff字体https://blog.csdn.net/qq_31747765/article/details/82356363此贴中有下载方法将字体保存在上述路径中mpl-data/fonts/tff的路径中打开第一步中得到的路径中matp
·
查找matplotlib字体安装路径
import matplotlib
print(matplotlib.matplotlib_fname())
下载simhei.tff字体
下载’SimHei’
将字体保存在上述路径中mpl-data/fonts/tff的路径中
打开第一步中得到的路径中matplotlibrc文件,将下述两行前的#去掉, 并在第二行加入SimHei字体
#font.family : sans-serif
#font.serif : SimHei, DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New
清除字体缓存
cd ~/.matplotlib/
rm -rf ~/.matplotlib/*.cache
rm -rf fontList.py3k.cache
在代码中加入下面两行
plt.rcParams[‘font.sans-serif’] = [‘SimHei’] # 用来正常显示中文标签
plt.rcParams[‘axes.unicode_minus’] = False # 用来正常显示负号
更多推荐
所有评论(0)