matplotlib库
乱码问题
matplotlib本身只支持ASCII,所以需要更改字体库
有几种方法可以解决中文乱码,这里采用更改配置一次到位
以下是mac环境,其他环境类似
- 查看字体文件注册名字 根据list找到对应字体库的注册名字…这里建议找能对应的上的
1
2
3import matplotlib
from matplotlib import font_manager
sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist]) - 把对应字体tff文件拷贝到,matplotlib安装目录下的mpl-data/fonts/tff中
更改mpl-data/matplotlibrc
1
2
3
4
5#font.family : sans-serif
#font.style : normal
#font.variant : normal
#font.weight : medium
#font.stretch : normal改成
1
font.family : 对应的注册名
即可
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 SHIELD!
评论