Advertisement

WARNING:matplotlib.font_manager:findfont: Generic family ‘sans-serif‘ not found because none of the

阅读量:

WARNING:matplotlib.font_manager:findfont: Generic family ‘sans-serif’ not found because none of the following families were found: SimHei

问题描述:python matplotlib缺少SimHei这种字体(黑体)

复制代码
    %matplotlib inline
    import matplotlib.pyplot as plt
    plt.rcParams['font.sans-serif'] = ['SimHei']   # 解决图表中文乱码问题
    
    
    python
    
    

画图时报错
在这里插入图片描述

解决方法

第一步,下载字体simhei

第二步,把字体放到相应的文件夹

到matplotlib包安装目录下,找到字体存放目录。
在这里插入图片描述
python310是我在anaconda下创建的一个虚拟环境

第三步,清除原有字体缓存

查看缓存目录

复制代码
    import matplotlib as mpl
    print(mpl.get_cachedir())
    
    
    python
    
    

在这里插入图片描述
定位缓存目录,并删除现有缓存
在这里插入图片描述

第四步,重起jupyter notebook

复制代码
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    plt.figure()
    plt.title("我是黑体")
    
    
    python
    
    

在这里插入图片描述
参考
百分百解决你的matplotlib画图中文乱码问题
plt.rcParams参数详解

全部评论 (0)

还没有任何评论哟~