matplotlib散点图
matplotlib散点图
��设通过爬虫你获取到了北京2016年3, 10月份每天白天的最高气温(分别位于列表a, b), 那么此时如何寻找出气温和随时间(天)变化的某种规律?
from matplotlib import pyplot as plt x_3 = range(1, 32) x_10 = range(51, 82) y_3 = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23] y_10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6] # 设置图形大小 plt.figure(figsize=(20, 8), dpi=80) # 绘制散点 plt.scatter(x_3, y_3, label="March") plt.scatter(x_10, y_10, label="October") x = list(x_3) + list(x_10) xtick_labels = ["March {}th".format(i) for i in x_3] xtick_labels += ["October {}th".format(i-50) for i in x_10] plt.xticks(x[::3], xtick_labels[::3], rotation=45) # 添加图例及描述信息 plt.legend(loc="best") plt.xlabel("day") plt.ylabel("temperature") plt.title("Temperature changes per day") plt.show()
The End