使用matplotlib库中文显示问题

风格不统一 提交于 2019-12-02 06:08:30
    from matplotlib import pyplot as plt, font_manager
    # 字体实例对象
    my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf")

    # 气温
    x=range(0,120)
    # 时间
    y=[random.randint(20,35) for i in range(120)]
    _x_labels=["10点{}分".format(i) for i in range(60)]
    _x_labels+=["11点{}分".format(i) for i in range(60)]

    plt.plot(x, y)
    # 设置中文显示 fontproperties
    plt.xticks(list(x)[::3],_x_labels[::3],rotation=45,fontproperties=my_font)
    plt.show()

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!