matplotlib learning Notes on a line chart

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()

Guess you like

Origin www.cnblogs.com/milesma/p/12134670.html