我想要一个在第一行有两个子图的图,每个子图跨越1.5列,在第二行有三个图,每个子图一列宽。matplotlib和gridspec可以做到这一点吗?从示例来看,似乎不可以。width_ratios
参数也不起作用,因为这会影响所有行。
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
fig = plt.figure(figsize=(10, 6))
gs = GridSpec(2, 3)
# First row (1.5 column width)
ax1 = plt.subplot(gs[0, 0])
ax2 = plt.subplot(gs[0, 1])
# Second row (one-third width)
ax3 = plt.subplot(gs[1, 0])
ax4 = plt.subplot(gs[1, 1])
ax5 = plt.subplot(gs[1, 2])
ax1.set_title('Subplot 1')
ax2.set_title('Subplot 2')
ax3.set_title('Subplot 3')
ax4.set_title('Subplot 4')
ax5.set_title('Subplot 5')
plt.tight_layout()
plt.show()
上面的代码产生了这个。我只是不知道如何使子图1和2跨越1.5列。
2条答案
按热度按时间44u64gxh1#
使用
subplot_mosaic
:输出:

z9ju0rcb2#
你可能会想做一个
2x6
网格:产出: