您可以使用子图2网格 https://matplotlib.org/users/gridspec.html。真的很方便。
文档说
在网格中创建子图。网格由形状指定,位于 loc 的位置,在每个方向上跨越 rowspan、colspan 单元格。 loc 的索引从 0 开始。
首先,根据行数和列数定义大小(3,2)
这里。然后定义特定子图的起始(行、列)位置。然后分配该特定子图跨越的行/列数。行和列跨度的关键字是rowspan
and colspan
分别。
import matplotlib.pyplot as plt
ax1 = plt.subplot2grid((3, 2), (0, 0), colspan=1)
ax2 = plt.subplot2grid((3, 2), (0, 1), colspan=1)
ax3 = plt.subplot2grid((3, 2), (1, 0), colspan=2)
ax4 = plt.subplot2grid((3, 2), (2, 0), colspan=2)
plt.tight_layout()