2016-03-02 14 views
5

我想減少子圖之間的垂直空間。沿着網上衝浪我剛剛發現如何降低的水平間距,像Matplotlib子圖中的垂直空間操作

import matplotlib.pyplot as plt 

fig, axes = plt.subplots(nrows=4, ncols=4) 
fig.tight_layout() # Or equivalently, "plt.tight_layout()" 
fig.subplots_adjust(hspace=0.5) 
plt.show() 

的HSPACE的是,操縱這種行爲的人,但顯然沒有VSPACE。

編輯:

這不會減少y軸之間的空間,這是我要處理什麼。

+0

您的代碼** **不降低垂直子圖之間的空間。 – DavidG

+0

我的意思是,它不會減小子圖中y軸之間的空間,這就是我想要做的。 – user2820579

+0

請再次閱讀,不要投反對票,因爲這個問題被誤解了! – user2820579

回答

6

正如您在您的問題中所述hspace減少了子圖之間的垂直間距。子圖之間的水平間距相當於wspace。下面是一個例子:

x = np.linspace(0, 2 * np.pi, 400) 
y = np.sin(x ** 2) 


fig, ((ax1,ax2),(ax3,ax4)) = plt.subplots(nrows=2, ncols=2) 
fig.tight_layout() 
ax1.plot(x, y) 
ax2.scatter(x, y) 
ax3.scatter(x, y) 
ax4.scatter(x, y) 

fig.subplots_adjust(wspace=0.2) 
plt.show() 

使用值1爲wspace給出 enter image description here

使用0.2作爲wspace的值給出

enter image description here

+0

wspace而不是hspace有多不直觀! – famargar

+0

我想'hspace'是_height_和'wspace'是_width_?但是,有點違反直覺! – DavidG