Python matplotlib 解决 “not found because none of the following families were found: Times New Roman“


1. 问题

在 Linux Ubuntu/Centos 系统下,Python 画图/保存图片出现报错:

not found because none of the following families were found: Times New Roman"

原因是缺少 “Times New Roman” 字体,需要手动下载

2. 解决步骤

2.1 下载 Times New Roman

# ubuntu
sudo apt-get update
sudo apt-get install ttf-mscorefonts-installer

# centos
yum install ttf-mscorefonts-installer

如果是非图形化的系统,会出现一个界面,移动上下左右键,选择 “OK”安装。

2.2 删除字体缓存

命令行输入:Python
进入到 Python 终端界面

import matplotlib as mpl
print(mpl.get_cachedir())

在这里插入图片描述
删除缓存:

rm -rf /root/.cache/matplotlib/*

2.3 下载字体

进入到 ~/.fonts 目录下(如果没有目录,那就创建 mkdir ~/.fonts

cd ~/.fonts

这里链接下载 SimHei 字体,或者执行下面命令:

wget http://129.204.205.246/downloads/SimHei.ttf

2.4 下载fc-cache命令

# centos 
sudo yum install fontconfig -y

# ubuntu
sudo apt-get install fontconfig -y

# mac
brew install fontconfig

刷新字体缓存

fc-cache -fv

3. 使用字体

import matplotlib.pyplot as plt
plt.rc('font', family="Times New Roman")
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SmallerFL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值