如何在matplotlib中创建具有不同wspace的子批次?

2024-05-23 16:54:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我们如何在它们之间创建具有不同wspace的子批。例如,我正在绘制5个图,第一行有2个,第二行有3个。我希望第一行有不同的wspace,最后3行的wspace=0。我不知道如何用其他参数来调整网格的大小

gs1 = gridspec.GridSpec(3, 3)
gs1.update(left=0.05, right=0.48, wspace=0.05)
ax1 = plt.subplot(gs1[:-1, :])
ax2 = plt.subplot(gs1[-1, :-1])
ax3 = plt.subplot(gs1[-1, -1])

gs2 = gridspec.GridSpec(3, 3)
gs2.update(left=0.55, right=0.98, hspace=0.05)
ax4 = plt.subplot(gs2[:, :-1])
ax5 = plt.subplot(gs2[:-1, -1])
ax6 = plt.subplot(gs2[-1, -1])

我不明白怎么回事

^{pr2}$

有效。谢谢您。在


Tags: right网格参数绘制updatepltleftgs1
1条回答
网友
1楼 · 发布于 2024-05-23 16:54:04

您有gridspec.GridSpec(3, 3)这意味着3行3列,总共有9个子批,索引为gs1[i,j], i - a row, j - a col。在

看看这个例子:

import numpy as np
A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

print A[:-1, :] # get first and second rows (that is -1 means does not include last elements (last row) 
print A[-1, :-1] # from last row get all columns except last
print A[-1, -1] # get last element of array A (that is A[2][2])

输出:

^{pr2}$

阅读python中的数组切片:http://structure.usc.edu/numarray/node26.html

相关问题 更多 >