matplotlib散點圖
假設通過爬蟲你獲取到了北京2016年3, 10月份每天白天的最高氣溫(分別位于列表a, b), 那么此時如何尋找出氣溫和隨時間(天)變化的某種規律?
from matplotlib import pyplot as pltx_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()