![](/img/trans.png)
[英]How to change the figure size of a seaborn axes or figure level plot
[英]How to set individual sub-figure size in seaborn plot?
我有一個繪制多個圖的代碼 - Seaborn 中的單個 plot 中的熱圖和條形圖。 但是,兩個圖的大小相同,即整體圖的一半是熱圖,另一半是條形圖。 有沒有辦法控制單個 plot 大小,使得熱圖占據 plot 大小的 75%,而條形圖只占據 Z32FA6E1B78A9D4028953E60564A2A4CZ 大小的 25%?
參考代碼:
ig, ax = plt.subplots(1, 2, figsize=(7, 5))
heatmap = np.random.uniform(0, 1, size=(12, 12))
sns.heatmap(heatmap_scores, linewidth=0.5, cmap="OrRd", ax=ax[0])
ax[0].set_xlabel('Head')
ax[0].set_ylabel('Layer')
ax[0].set_title('Attention Heatmap')
x = np.mean(heatmap_scores, axis=1)
y = np.arange(0, 12)
sns.barplot(x=x, y=y, ax=ax[1], orient='h', color='r', dodge=False)
ax[1].set_title('Layer Average')
ax[1].set(yticklabels=[])
plt.savefig('fig.png')
plt.close()
您可以使用鍵gridspec_kw
自定義GridSpec
選項,將它們傳遞給subplots
:
fig, ax = plt.subplots(1, 2, figsize=(7, 5), gridspec_kw={'width_ratios': [.75, .25]})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.