findfont: Generic family ‘sans-serif‘ not found because none of the following families were found: S

every blog every motto: You can do more than you think.
https://blog.csdn.net/weixin_39190382?type=blog

0. 前言

错误记录

findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei

1. 正文

1.1 问题

findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei

1.2 解决方法

  1. 删除缓存
import matplotlib as mpl
print(mpl.get_cachedir())

会输出类似如下地址,

/home/v/.cache/matplotlib

删除该地址中的文件

rm -r /home/v/.cache/matplotlib/*
  1. 下载字体
    点击下载
    放到~/.fonts目录下,若没有需创建一个
mkdir ~/.fonts
  1. 刷新

此步未执行,已成功

fc-cache -fv

参考

[1] https://zhuanlan.zhihu.com/p/566430362

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
回答: 这个问题是由于找不到字体家族'sans-serif'导致的。根据引用\[1\]和引用\[2\]的报错信息,可以看出在系统中找不到SimHei字体。为了解决这个问题,你可以按照引用\[3\]中的步骤进行操作。首先,在Python环境中输入以下代码来查看字体路径:import matplotlib matplotlib.matplotlib_fname()。这将显示matplotlib的配置文件路径。然后,你可以将SimHei字体文件复制到该路径下的字体文件夹中。这样,当你再次运行程序时,就能够找到并使用SimHei字体了。 #### 引用[.reference_title] - *1* [解决linux服务器上matplotlib绘图中文显示方框问题](https://blog.csdn.net/liu_xzhen/article/details/122881997)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [linux下python matplotlib 中文字体Font family [‘sans-serif‘] not found. Falling back to DejaVu Sans](https://blog.csdn.net/sinat_36728101/article/details/124349841)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [解决使用matplotlib.pyplot画图包含中文乱码显示问题(macbook上 family ‘sans-serif‘ not found 问题)](https://blog.csdn.net/ben_na_/article/details/124238611)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

胡侃有料

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

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

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

打赏作者

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

抵扣说明:

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

余额充值