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)

  • 相关阅读:
    util包的常用类及其方法(下)
    util包的常用类及其方法(上)
    每日一记--java基础01
    每日一记--java细节之问01
    每日一记--设计模式01
    每日一记--JVM虚拟机01
    每日一记--java基础之final/static/事务
    每日一记--Mysql错误代码1067
    每日一记--AOP
    每日一记--代理模式
  • 原文地址:https://www.cnblogs.com/nxld/p/6075026.html
Copyright © 2011-2022 走看看