多个坐标系显示plt.subplots(面向对象的画图方法)
会返回两个对象,那么如何对单独的对象进行操作?
axes[0]
axes[1]
.方法名调用
x = range(60)
y_shanghai = [random.uniform(15,18) for i in x]
y_beijing = [random.uniform(1,3) for i in x]
figure , axes = plt.subplots(nrows=1, ncols=2, figsize=(20,8),dpi=80)
axes[0].plot(x,y_shanghai, color="r", linestyle="--", label="上海")
axes[1].plot(x,y_beijing, color="b",label="北京")
axes[0].legend()
axes[1].legend()
x_label = ["11点{}分".format(i) for i in x]
axes[0].set_xticks(x[::5], x_label[::5])
axes[0].set_yticks(range(0,40,5))
axes[1].set_xticks(x[::5], x_label[::5])
axes[1].set_yticks(range(0,40,5))
axes[0].grid(True, linestyle="--", alpha =0.5)
axes[1].grid(True, linestyle="--", alpha =0.5)
axes[0].set_xlabel("时间")
axes[0].set_ylabel("温度")
axes[0].set_title("上海11点0分到12点之间的温度变化表示")
axes[1].set_xlabel("时间")
axes[1].set_ylabel("温度")
axes[1].set_title("北京11点0分到12点之间的温度变化表示")
plt.show()
折线图的应用场景
呈现公司产品(不同区域)每天活跃用户数
呈现app每天下载数量
呈现产品功能上线后,用户点击次数随时间的变化
绘制数学函数图像