您链接到的帖子的答案将对您有所帮助,但目前最简单的方法(自matplotlib-3.3.0以来)可能是使用plt.subplot_mosaic
,并将高度比传递给gridspec_kw
参数.
例如
fig, axes = plt.subplot_mosaic("AB;CD;EE", gridspec_kw=dict(height_ratios=[1, 1, 0.5]))
这会给你
This returns axes
as a dictionary of Axes
with the name you give it, so you can plot with 例如
axes["A"].plot([1, 2, 3], [1, 2, 3])
(您也可以像这样"双叠"马赛克,以获得相同的效果,而无需使用gridspec_kw
)
fig, axes = plt.subplot_mosaic("AB;AB;CD;CD;EE")
如果出于某种原因,你不想(或不能)使用suplot_mosaic
,那么你可以直接使用GridSpec
(example here).
from matplotlib.gridspec import GridSpec
fig = plt.figure()
gs = GridSpec(nrows=3, ncols=2, figure=fig, height_ratios=[1, 1, 0.5])
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, 0])
ax4 = fig.add_subplot(gs[1, 1])
ax5 = fig.add_subplot(gs[2, :])
这会给你 the same thing.