我试图弄明白子地块索引是如何工作的,但它们看起来一点都不直观。我特别对第三个指数有意见。我知道在python中还有其他方法可以创建子图,但我正在努力理解以这种方式编写的子图是如何工作的,因为它们被广泛使用。
我试着用一个琐碎的例子来看看我是否理解我在做什么。所以,我想做的是:
- 第1行有3列
- 第2行有2列
- 第3行有3列
- 第4行和第5行有2列。但是,我希望左边的子地块横跨第4行和第5行
这是前3行的代码。我不明白为什么ax4
的第三个索引是3而不是4。
ax1 = plt.subplot(5,3,1)
ax2 = plt.subplot(5,3,2)
ax3 = plt.subplot(5,3,3)
ax4 = plt.subplot(5,2,3)
ax5 = plt.subplot(5,2,4)
ax6 = plt.subplot(5,3,7)
ax7 = plt.subplot(5,3,8)
ax8 = plt.subplot(5,3,9)
对于第3行和第4行的三个子情节,我似乎无法做到这一点。这是我错误的尝试:
ax9 = plt.subplot(4,2,10)
ax10 = plt.subplot(5,2,12)
ax11 = plt.subplot(5,2,15)
索引从左到右,然后换行到行的末尾。所以subplot(2, 3, x)
:
1 2 3
4 5 6
以ax4=subplot(5, 3, x)
为例,子地块被编入索引:
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
对于ax4=subplot(5, 2, x)
,它们被编入索引:
1 2
3 4
5 6
7 8
9 10
要跨越子地块,您可以输入开始和停止索引:
ax9 = plt.subplot(5, 2, 7:9)
ax10 = plt.subplots(5, 2, 8:10)