Matplotlib 如何显示中文

来源:互联网 发布:二选一数据选择器 编辑:程序博客网 时间:2024/05/16 19:39

Python 3.x

主要是如下代码

import osfont = 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 FontPropertiesimport matplotlib.pyplot as pltimport osfont = 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()
1 0
原创粉丝点击