在Matplotlib中定位5个子图
发布于 2021-01-29 16:06:11
我想对5个子图进行定位,以使顶部有3个,底部有2个,但彼此相邻。当前代码已接近,但我希望最终结果如下所示(忽略灰线):
import matplotlib.pyplot as plt
ax1 = plt.subplot(231)
ax2 = plt.subplot(232)
ax3 = plt.subplot(233)
ax4 = plt.subplot(234)
ax5 = plt.subplot(236)
plt.show()
关注者
0
被浏览
198
1 个回答
-
您可以在使用suplot2grid而不是subplot时使用colspan。
import matplotlib.pyplot as plt ax1 = plt.subplot2grid(shape=(2,6), loc=(0,0), colspan=2) ax2 = plt.subplot2grid((2,6), (0,2), colspan=2) ax3 = plt.subplot2grid((2,6), (0,4), colspan=2) ax4 = plt.subplot2grid((2,6), (1,1), colspan=2) ax5 = plt.subplot2grid((2,6), (1,3), colspan=2)
然后,每个子图都需要2个cols宽,以便第二行中的子图可以移动1列。