linux下python matplotlib 中文字体Font family [‘sans-serif‘] not found. Falling back to DejaVu Sans

linux下python matplotlib 中文字体Font family [‘sans-serif‘] not found. Falling back to DejaVu Sans,第1张

问题

在linux新的python环境,安装了matplotlib,但是使用中文字体时找不到。
问题代码:

import  matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']  # 中文字体设置

报错:

findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei
解决

首先,下载需要的字体。
然后将字体放到 /site-packages/matplotlib/mpl-data/fonts/ttf下。
找到python字体缓存文件:

import matplotlib
print(matplotlib.get_cachedir())
/root/.cache/matplotlib

删除缓存:

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

重新运行即可。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/717579.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-25
下一篇2022-04-25

发表评论

登录后才能评论

评论列表(0条)

    保存