You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装导入yellowbrick后matplotlib可用字体缺失问题咨询

导入yellowbrick后Matplotlib字体缺失导致图表异常

安装并导入yellowbrick模块后,Matplotlib无法找到图表标签、标题所需的Arial、Liberation Sans、Bitstream Vera Sans等无衬线字体,抛出如下警告:

findfont: Generic family 'sans-serif' not found because none of the following families were found: Arial, Liberation Sans, Bitstream Vera Sans, sans-serif

图表可视化效果因此异常,对比如下:

正常显示效果
正常图表效果

异常显示效果
异常图表效果


解决办法

1. 安装缺失字体

根据操作系统安装对应无衬线字体:

  • Windows/macOS:确保Arial字体已安装(系统通常自带,缺失可从官方渠道下载)
  • Linux(Ubuntu/Debian):执行命令安装Liberation Sans:
sudo apt-get install fonts-liberation

2. 重置Matplotlib字体缓存

安装字体后,清除缓存让Matplotlib识别新字体:

import matplotlib
matplotlib.font_manager._load_fontmanager.cache_clear()

也可手动删除缓存文件:

  • Linux:~/.cache/matplotlib/fontlist-v330.json
  • Windows:C:\Users\<你的用户名>\.matplotlib\fontlist-v330.json
  • macOS:~/Library/Caches/matplotlib/fontlist-v330.json

3. 手动指定默认字体

若不想安装新字体,直接指定系统已有的无衬线字体(如SimHei、Noto Sans):

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Noto Sans']  # 替换为你系统存在的字体
plt.rcParams['axes.unicode_minus'] = False  # 修复负号显示问题

4. 提前设置Matplotlib字体

yellowbrick可能覆盖Matplotlib配置,可在导入yellowbrick前先指定字体:

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Arial', 'Liberation Sans', 'sans-serif']
from yellowbrick import *

内容的提问来源于stack exchange,提问作者guilistocco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 02:50:50