如何添加matplotlib中的字体(以Times New Roman字体为例)

参考链接:(14条消息) python绘图之Times New Roman字体以及Helvetica字体_燕策西的博客-CSDN博客_python画图字体如何设置新罗马

 

下面以如何添加Times New Roman字体为例:

  • 获取目标文件——times.ttf(笔者就在自己的windows系统中用Everything搜索得到了此文件);
  • 将times.ttf文件复制到当前conda环境下的lib/python3.x/site-packages/matplotlib/mpl-data/fonts/ttf/文件夹中;
  • 获取matplotlib的缓冲目录:
import matplotlib
print(matplotlib.get_cachedir())
  • 删除matplotlib的缓冲目录:
rm -rf [cachedir]
  • 再次import matplotlib时即可使用Times New Roman字体;

posted on 2022-10-22 17:36  穷酸秀才大草包  阅读(2228)  评论(0)    收藏  举报

导航