wsl中matplotlib安装中文字体

发布时间 2023-10-08 09:40:49作者: 逝痕枫舞

wsl中matplotlib安装中文字体

首先修改matplotlib配置的中文字体

  1. 使用python定位字体路径

import matplotlib
matplotlib.matplotlib_fname()
  1. 打开电脑的C:windows/fonts下,查找yahei关键字,将微软雅黑ttf字体拷贝,扔到wsl中显示的路径下的fonts/ttf文件夹里面。

  2. 删除matplotlib缓存

cd ~/.cache/matplotlib
rm * -r
  1. 修改matplotlibrc文件:修改font.sans-serif 加入中文字体
font.sans-serif     : Microsoft YaHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif,

img

  1. 重新启动即可