如何使用 subplot2grid 增加 Matplotlib 中子圖之間的間距?


要使用subplot2grid增加子圖之間的間距,我們可以採取以下步驟 -

  • 設定圖形大小並調整子圖之間和周圍的間距。

  • 新增網格佈局以在一個圖形中放置子圖。

  • 更新網格的子圖引數。

  • 將子圖新增到當前圖形中。

  • 要顯示圖形,請使用show()方法。

示例

from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

ax = plt.GridSpec(2, 2)
ax.update(wspace=0.5, hspace=0.5)

ax1 = plt.subplot(ax[0, :])
ax2 = plt.subplot(ax[1, 0])
ax3 = plt.subplot(ax[1, 1])

plt.show()

輸出

更新於: 2021 年 9 月 23 日

8 千次+ 檢視

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.