Linux matplotlib 中文乱码(小框框的问题) jupyter-notebook
复制字体文件夹过去Linux上
把Windows的字体C:/Windows/Fonts
复制到Linux系统的存放字体路径/usr/share/fonts
下, 如图:
cd到/usr/share/fonts/Fonts
,也就是拷贝来的文件夹, 建立字体索引信息,更新字体缓存,让字体生效, 运行命令:
mkfontscale && mkfontdir && fc-cache -fv && source /etc/profile && fc-list |wc -l
查看字体fc-list :lang=zh
加载字体
import matplotlib
#指定默认字体
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family']='sans-serif' #解决负号'-'显示为方块的问题
matplotlib.rcParams['axes.unicode_minus'] = False
可以正常显示中文了
记得重启jupyter notebook试一下
如果还不行,则清除一下缓存再重启
如果添加了第二部的配置,但还是显示中文乱码, 那么有可能是缓存的问题, 执行rm -r ~/.cache/matplotlib