Matplotlib 如何显示中文

Python 3.x

主要是如下代码

import os
font = FontProperties(fname=os.path.expandvars(r"%windir%\fonts\simsun.ttc"), size=14)
plt.xlabel("测试", fontproperties=font)
# coding:utf-8
# from __future__ import unicode_literals #Python 3.x 不需要此行
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
import os
font = FontProperties(fname=os.path.expandvars(r"%windir%\fonts\simsun.ttc"), size=14)
from numpy import *
import operator



__author__ = 'norsd@163.com'


# 代码段忽略
# 代码段忽略

# 快速运行函数
def run_helper():    
    import matplotlib
    import matplotlib.pyplot as plt
    fig = plt.figure()
    plt.xlabel("测试", fontproperties=font)
    plt.ylabel("ABC")
    ax = fig.add_subplot(111)
    ax.scatter(a[:, 0], a[:, 1], 15.0*array(b), 15.0*array(b))
    plt.show()


if __name__ == '__main__':
    run_helper()

posted on 2016-01-27 01:39  norsd  阅读(187)  评论(0编辑  收藏  举报

导航