• python matplotlib 中文显示参数设置


    python matplotlib 中文显示参数设置

    方法一:
    每次编写代码时进行参数设置

    #coding:utf-8
    import matplotlib.pyplot as plt
    plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
    plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
    #有中文出现的情况,需要u'内容'
    方法二:
    import matplotlib
    matplotlib.matplotlib_fname() #将会获得matplotlib包所在文件夹
    然后进入C:Anaconda64Libsite-packagesmatplotlibmpl-data该文件夹下就能看到matplotlibrc配置文件。2

    1)打开该配置文件,找到下面这行:

    #font.serif : Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
    然后,将前面的注释去掉!
    2)找中文字体放到matplotlib字体库中。
    在Windows文件夹下:C:WindowsFontsMicrosoft YaHei UI复制该字体,然后粘贴到C:Anaconda64Libsite-packagesmatplotlibmpl-datafonts tf文件夹,并给它重命名为Vera.ttf。

    注明:这一步的作用其实就是将matplotlib中一个默认的字体替换为我们复制过来的中文字体,将这个中文字体命名改为matplotlib中有的字体名。3
    方法三:
    import sys
    default_encoding = 'utf-8'
    if sys.getdefaultencoding() != default_encoding:
    reload(sys)
    sys.setdefaultencoding(default_encoding)

  • 相关阅读:
    UVA 12546 LCM Pair Sum
    两两间的距离都是整数的点集
    Codeforces 11.27
    Codeforces 11.27 B
    UVA 105
    打印自身的程序
    Interval DP
    Tree DP
    参加第五次全国工程建设行业信息化建设高峰论坛 (个人的一点感想)
    基础资料分类及清单版本管理
  • 原文地址:https://www.cnblogs.com/nxld/p/6075026.html
Copyright © 2020-2023  润新知