一、三层架构
1.容器层
2.辅助层
3.图像层
二、图像保存、xy轴刻度、网格
# 0.生成数据
x = range(60)
y_beijing = [random.uniform(10,15) for i in x]
y_shanghai = [random.uniform(15,25) for i in x]
# 1.创建画布
plt.figure(figsize=(20,8),dpi=100)
# 2. 图形绘制
plt.plot(x,y_beijing,label = "北京",color = "g", linestyle="-.")
plt.plot(x,y_shanghai,label = "上海")
# 2.1 添加x,y轴刻度
x_ticks_labels = ["11点{}分".format(i) for i in x]
plt.xticks(x[::5],x_ticks_labels[::5])
y_ticks = range(40)
plt.yticks(y_ticks[::5])
# 2.2 添加网格
plt.grid(True,linestyle="--",alpha = 0.5)
# 2.3 添加描述
plt.xlabel("时间")
plt.ylabel("温度")
plt.title("标题",fontsize=20)
# 2.4 显示图例
plt.legend(loc=0)
# 3.图像展示
plt.show()
三、一个坐标系画多条线
# 0.生成数据
x = range(60)
y_beijing = [random.uniform(10,15) for i in x]
y_shanghai = [random.uniform(15,25) for i in x]
# 1.创建画布
plt.figure(figsize=(20,8),dpi=100)
# 2. 图形绘制
plt.plot(x,y_beijing,label = "beijing",color = "g", linestyle="-.")
plt.plot(x,y_shanghai,label = "shanghai")
# 2.1 添加x,y轴刻度
x_ticks_labels = ["11:{}".format(i) for i in x]
plt.xticks(x[::5],x_ticks_labels[::5])
y_ticks = range(40)
plt.yticks(y_ticks[::5])
# 2.2 添加网格
plt.grid(True,linestyle="--",alpha = 0.5)
# 2.3 添加描述
plt.xlabel("time")
plt.ylabel("wendu")
plt.title("titile",fontsize=20)
# 2.4 显示图例
plt.legend(loc=0)
# 3.图像展示
plt.show()
四、多个坐标系画图
# 0.生成数据
x = range(60)
y_beijing = [random.uniform(10,15) for i in x]
y_shanghai = [random.uniform(15,25) for i in x]
# 1.创建画布
fig,axes = plt.subplots(nrows=1,ncols=2,figsize=(20,8),dpi=100)
# 2. 图形绘制
axes[0].plot(x,y_beijing,label = "beijing",color = "g", linestyle="-.")
axes[1].plot(x,y_shanghai,label = "shangahi")
# # 2.1 添加x,y轴刻度
x_ticks_labels = ["11:{}".format(i) for i in x]
y_ticks = range(40)
axes[0].set_xticks(x[::5])
axes[0].set_yticks(y_ticks[::5])
axes[0].set_xticklabels(x_ticks_labels[::5])
axes[1].set_xticks(x[::5])
axes[1].set_yticks(y_ticks[::5])
axes[1].set_xticklabels(x_ticks_labels[::5])
# # 2.2 添加网格
axes[0].grid(True,linestyle="--",alpha = 0.5)
axes[1].grid(True,linestyle="--",alpha = 0.5)
# # 2.3 添加描述
axes[0].set_xlabel("time")
axes[0].set_ylabel("wendu")
axes[0].set_title("title",fontsize=20)
axes[1].set_xlabel("time")
axes[1].set_ylabel("wendu")
axes[1].set_title("title",fontsize=20)
# 2.4 显示图例
axes[0].legend(loc=0)
axes[1].legend(loc=0)
# 3.图像展示
plt.show()