zoukankan      html  css  js  c++  java
  • 解决python matplotlib 中文字体的显示乱码-Windows系统;RuntimeWarning: Glyph

    matplotlib乱码问题

    全部乱码

    显示乱码如下:

    RuntimeWarning: Glyph 22833 missing from current font.
    

    直接使用很多博客中的方法,就是直接设置font.sans-seriffont.family等。

    import matplotlib.pyplot as plt
    plt.rcParams['font.sans-serif'] = ['simhei']###解决中文乱码
    plt.rcParams['axes.unicode_minus']=False
    

    但是上面的这个方法只能解决,除了plt.legend以外的部分的乱码。因为还是有一部分有乱码

    对于plt.legend部分标签中文乱码问题

    解决了上述问题后,还是有其plt.legend`部分标签中文乱码问题。针对这个部分的乱码,我最终归结为,这个部分需要特殊处理,因此我添加了如下代码,下面的代码是全部包含的:

    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    
    plt.rcParams['font.sans-serif'] = ['simhei']###解决中文乱码
    plt.rcParams['axes.unicode_minus']=False
    

    下面就是在使用plt.legend的时候,添加你的字体路径的相关了类型。注意这个目录下要有这个simhe=>simple character heiti 简体黑体字吧

    my_font = FontProperties(fname=r"C:WindowsFontssimhei.ttf")
    plt.legend(['精确度','损失'], loc=4,
                   fontsize=8,prop=my_font)
    
  • 相关阅读:
    数据校验
    Struts2中OGNL
    Struts2 入门(新手必看)
    transactionManager 以及datasource type解析
    MyBatis
    rails 布署
    ubuntu ssh
    ubutun 下配置php和postgresql
    MS SQL 数据库所在C盘变得很大解决办法
    将表里的数据批量生成INSERT语句的存储过程 增强版
  • 原文地址:https://www.cnblogs.com/SsoZhNO-1/p/14391358.html
Copyright © 2011-2022 走看看