簡體   English   中英

python - matplotlib:figsize for subplots - 在行之間添加空格

[英]python - matplotlib : figsize for subplots - adding space between rows

我使用以下代碼制作圖:

   fig, axes = plt.subplots(len(pairs), 3, figsize=(12, 324))
    for i, pair in enumerate(pairs):
        d = pd.DataFrame(columns=[pairs[0], pairs[1]])
        e = df_norm[list(pair)]
        ax0 = axes[i,0]
        ax1 = axes[i,1]
        ax2 = axes[i,2]

        d[pair[0]] = np.random.normal(e[pair[0]],0.02)
        d[pair[1]] = np.random.normal(e[pair[1]],0.02)

    d.plot.scatter(*pair, ax=ax0, c=col0, linewidths=0, s=2, alpha = 0.7)
    d.plot.scatter(*pair, ax=ax1, c=col1, linewidths=0, s=2, alpha = 0.7)
    d.plot.scatter(*pair, ax=ax2, c=col2, linewidths=0, s=2, alpha = 0.7)

fig.tight_layout()

但是,我的輸出圖都搞砸了:

在此輸入圖像描述

我嘗試通過使324更大或更小來改變figsize=(12, 324) ,但都沒有幫助。 有沒有辦法我可以在每一行之間放置一些空格,這樣數字就不會搞砸了。 謝謝!

你需要ommit fig.tight_layout()而使用subplots_adjust

plt.subplots_adjust(top = 0.99, bottom=0.01, hspace=1.5, wspace=0.4)

有一些非常極端的價值觀。 hspace是子圖之間的垂直間隙(最可能以子圖高度為單位)。

Figure具有相同的subplots_adjust方法,因此您可以決定選擇哪一個。

在我看來,最簡單的方法是堅持使用fig.tight_layout並使用h_pad (用於高度)和w_pad (用於寬度)。 例如:

fig.tight_layout(h_pad=5, w_pad=5)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM