![linux下python matplotlib 中文字体Font family [‘sans-serif‘] not found. Falling back to DejaVu Sans,第1张 linux下python matplotlib 中文字体Font family [‘sans-serif‘] not found. Falling back to DejaVu Sans,第1张](/aiimages/linux%E4%B8%8Bpython+matplotlib+%E4%B8%AD%E6%96%87%E5%AD%97%E4%BD%93Font+family+%5B%E2%80%98sans-serif%E2%80%98%5D+not+found.+Falling+back+to+DejaVu+Sans.png)
在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/*
重新运行即可。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)