subplot多合一画图

本文介绍了如何使用Python的matplotlib库通过subplot函数实现多图合一的画图技巧。通过实例展示了如何将figure划分为2*2的区块,并详细解释了不同写法的含义,以及如何对每个子图ax进行独立的操作,如设置标题、坐标轴等。
摘要由CSDN通过智能技术生成
import matplotlib.pyplot as plt

plt.figure()

plt.subplot(2, 2, 1)
plt.plot([0, 1], [0, 1])

plt.subplot(2, 2, 2)
plt.plot([4, 1], [0, 1])

plt.subplot(2, 2, 3)
plt.plot([0, 2], [0, 1])

plt.subplot(2, 2, 4)
plt.plot([0, 1], [0, 4])

plt.show()

plt.subplot(2, 2, 1)------把figure分成2*2的块,并在第一个画图
在这里插入图片描述

那如果我们要达到下图的效果怎么做呢?
在这里插入图片描述
仔细看怎么分的块

plt.figure()

plt.subplot(2, 1, 1)
plt.plot([0, 1], [0, 1])

plt.subplot(2, 3, 4)
plt.plot([4, 1], [0, 1])

plt.subplot(2, 3, 5)
plt.plot([0, 2], [0, 1])

plt.subplot(2, 3, 6)
plt.plot([0, 1], [0, 4])

plt.show()

另外一种写法比较好理解
可以分别对ax进行操作,但是方法前面都加有set_

plt.figure()
ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3, rowspan=
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值