• matplotlib折线图学习小记


    import matplotlib.pyplot as plt
    from tools.plt_test import weather
    # %matplotlib inline
    
    weathers = weather.weather_day()    # 获取最近七天天气的方法
    x = []      # 存放近七天的日期
    low = []    # 存放近七天的最低温度
    high = []   # 存放近七天的最高温度
    # 获取数据填充列表
    for i in weathers:
        print(weathers[i])
        x.append(weathers[i]['time'])
        low.append(int(weathers[i]['min_degree']))
        high.append(int(weathers[i]['max_degree']))
    
    # figsize 画布长宽, dpi 清晰度
    plt.figure(figsize=(12, 6), dpi=100)
    
    # 显示中文
    plt.rcParams['font.sans-serif'] = ['SimHei']
    # 解决无法显示负号
    plt.rcParams['axes.unicode_minus'] = False
    # 设置标题
    plt.title('天气走势图')
    # x轴描述
    plt.xlabel('日期')
    # y轴描述
    plt.ylabel('温度')
    # 添加网格显示,linestyle网格样式,alpha透明度
    plt.grid(linestyle=':', alpha=0.5)
    
    # 一条折线
    plt.plot(x, low, label='最高温')
    # 另一条折线
    plt.plot(x, high, label='最低温')
    # 右上角显示图例
    plt.legend()
    
    # 保存图像
    plt.savefig('weather.png')
    plt.show()
    

  • 相关阅读:
    函数式编程,高阶函数,纯函数,函数柯里化
    JS防抖与节流
    闭包使用场景
    Promise 内部实现
    视图组件
    认证 权限 频率控制 组件
    序列化组件
    Django之中间件及Auth认证模块
    Cookie,Session
    forms组件
  • 原文地址:https://www.cnblogs.com/milesma/p/12134670.html
Copyright © 2020-2023  润新知