zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    第01篇 说一下Setting,我一直没有讲过
    簡單委託介紹
    委託和事件
    wcf
    網站和項目的發佈問題
    jquery和js使用技巧
    js中String.prototype.format類似于.net中的string.formitz效果
    [剑指Offer] 6.旋转数组的最小数字(二分法)
    [剑指Offer] 5.用两个栈实现队列
    [剑指Offer] 4.重建二叉树
  • 原文地址:https://www.cnblogs.com/nxld/p/6075026.html
Copyright © 2011-2022 走看看