wsl安装字体与配置mlt

wsl默认是没有中文字体的,所以使用matplotlib绘图时存在中文就无法显示。所以本篇记录一下如何安装ttf字体,以及在Matplotplotlib中增加该字体。


[TOC]


安装字体

下载字体

直接百度搜索下载SimHei字体,就可以找到对应网页进行下载。

更改路径与权限

  • 拷贝字体到 usr/share/fonts
sudo cp SimHei.ttf  /usr/share/fonts/SimHei.ttf
  • 更改该文件夹的权限
sudo chmod 777 /usr/share/fonts

配置matplotlib

删除原来的缓存

  • 找到缓存路径

  • 删除缓存
sudo rm -rf /home/liu/.cache/matplotlib

修改配置

  • 找到配置文件路径

  • 编辑配置文件
sudo nano /home/liu/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc

添加下列数据:

font.family : sans-serif
font.sans-serif : SimHei
axes.unicode_minus : False
  • 重启jupyter即可

Enjoy it !

-------------本文结束感谢您的阅读-------------