一.下载中文字体(https://pan.baidu.com/s/1EqabwENMxR2WJrHfKvyrIw 这里下载多是SImhei字体)

安装字体:
解压:unzip SimHei.zip
拷贝字体到 usr/share/fonts 下(记得切换到.ttf的目录下面)

sudo cp ./SimHei.ttf /usr/share/fonts/SimHei.ttf

 

二. 查找matplotlib的配置目录

python 
import matplotlib
print(matplotlib.matplotlib_fname())

结果如下图所示

解决Ubuntu 16.04 环境下Python 无法显示中文的问题

三:更改matplotlib配置

sudo gedit /home/huster/anaconda3/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc

重点修以下三个地方(对应多注释#要去掉):

1.font.family : sans-serif

2.font.sans-serif: 这个字段要加上下载的中文字体名字,笔者使用多是Simhei,那么在后面字段的段首加上 Simhei

3.axes.unicode_minus : False

四:删除matplotlib字体缓存

python
import matplotlib 
print(matplotlib.get_cachedir())

找到对应对应的缓存目录,然后rm该目录下的fontList.json文件

sudo rm /home/huster/.cache/matplotlib/fontList.json 

 

相关文章:

  • 2022-12-23
  • 2021-09-15
  • 2021-07-18
  • 2022-12-23
  • 2021-06-01
  • 2022-01-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-10-03
  • 2022-01-07
  • 2021-04-17
相关资源
相似解决方案