Matplotlib笔记:多个坐标系显示

import matplotlib.pyplot as plt
import random
# 1.准备数据
x = range(60)
y_shanghai = [random.uniform(15, 18) for i in x]
y_beijing = [random.uniform(1, 3) for i in x]
# 2.创建画布
# plt.figure(figsize=(10, 4), dpi=80)
figure, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 4), dpi=80)
# 3.绘制图像
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()
# 4.添加自定义x,y
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))
# 5 添加网络显示
axes[0].grid(True, linestyle="--", alpha=0.5)
axes[1].grid(True, linestyle="--", alpha=0.5)
# 6.添加描述信息
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.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
# 7.显示图
plt.show()
 

 

转载于:https://www.cnblogs.com/jumpkin1122/p/11509755.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值