zoukankan      html  css  js  c++  java
  • matplotlib库的应用

    1、导入模块

    from matplotlib import pyplot as plt

    2、设置x,y的参数

    x = range(2,26,2)
    y = [15,13,14,5,17,20,25,26,26,27,22,18]

    3、绘制图片plot

    plt.plot(x, y)

    4、显示图形

    plt.show()

    保存图片

    plt.savefig("./t1.png")

    设置图片大小

    plt.figure(figsize=(20 , 9),dpi=88)

    设置x,和y的刻度

    plt.xticks(x)
    plt.yticks(y)

    设置中文

    导入模块
    from
    matplotlib import font_manager

    设置字体路径
    myfont = font_manager.FontProperties(fname="C:WindowsFontssimkai.ttf")


    fontproperties显示你的字体
    plt.title("10点到12点气温变化情况", fontproperties = myfont)
     

    字体倾斜度 rotation

    plt.xticks(x,rotation = 45)

    显示标题

    # x轴下方
    plt.xlabel("时间", fontproperties = myfont)
    
    # y轴左边
    plt.ylabel("温度", fontproperties = myfont)
    
    # 正上方标题
    plt.title("10点到12点气温变化情况", fontproperties = myfont)

    添加图例

    # 添加图例
    plt.plot(x,y,label = "自己")
    #设置图例字体
    plt.legend(prop = myfont)

    绘制网格线

    #绘制网格线
    plt.grid()
    #设置网格线的透明度
    plt.grid(alpha = 0.5)



  • 相关阅读:
    1822. Sign of the Product of an Array
    1828. Queries on Number of Points Inside a Circle
    1480. Running Sum of 1d Array
    C++字符串
    Git&GitHb学习记录
    54. Spiral Matrix
    104. Maximum Depth of Binary Tree
    110. Balanced Binary Tree
    136. Single Number
    19、泛型入门
  • 原文地址:https://www.cnblogs.com/wocaonidaye/p/12763953.html
Copyright © 2011-2022 走看看