# coding = utf - 8 from matplotlib import pyplot as plt y_3 = [11,17,16,11,12,11,12,6,6,7,8,9,12] y_10 = [26,26,28,19,21,17,16,19,18,20,19,17,23] x_3 = range(1, 14) x_10 = range(21, 34) # 设置图形大小 plt.figure(figsize=(12, 6), dpi=80) # 使用scatter绘制散点图和之前绘制折线图的唯一区别 plt.scatter(x_3, y_3, label = "March") plt.scatter(x_10, y_10, label = "October") # 调整x轴的刻度 _x = list(x_3) + list(x_10) _xtick_labels = ["March {}".format(i) for i in x_3] _xtick_labels += ["October {}".format(i - 20) for i in x_10] plt.xticks(_x[::3], _xtick_labels[::3], rotation = 45) # 添加描述信息 plt.xlabel("time") plt.ylabel("temperature ") plt.title("title") # 添加图例 plt.legend() # 展示 plt.show()