import pandas as pd
import matplotlib.pyplot as plt
#解决中文乱码问题
plt.rcParams['font.sans-serif']=['Arial Unicode Ms'] #解决中文乱码
#数据
plt.figure(figsize=(15,7),frameon=True)
highest = [26,21,26,26,22,20,17,19,22,28,30,28,24,28,25,26,25,26,25,23,24,30,32,31,30,27,26,27,29,25,25]
lowest = [17,13,17,18,18,17,14,15,16,18,19,20,18,18,20,20,20,20,20,16,17,19,21,24,24,23,20,18,19,18,19]
x=range(1,32,1)
plt.grid(axis='y')
#绘图
plt.plot(x,highest,color='r',marker='*',label="最高气温")
plt.plot(x,lowest,color='b',marker='o',label="最低气温")
plt.legend()
plt.xlabel('日期/天')
plt.ylabel('气温/C')
plt.title("5月份气温走势")
plt.xticks(range(1,32,1))
for a,b in zip(x,highest):
plt.text(a,b+0.5,b)
for c,d in zip(x,lowest):
plt.text(c,d+0.5,d)
plt.show()
【matplotlib】学习记录001.绘制折线图
最新推荐文章于 2024-09-15 22:31:42 发布