2011-02-22 70 views
22

的相對大小,我有兩個地塊的Python/Matplotlib - 更改插曲

import matplotlib.pyplot as plt 
plt.subplot(121) 
plt.subplot(122) 

我想plt.subplot(122)是一半寬plt.subplot(121)。是否有直接的方法來設置子圖的高度和寬度參數?

+0

可能重複[Matplotlib不同大小的子圖](http://stackoverflow.com/questions/10388462/matplotlib-different-size-subplots) – Vincenzooo 2017-02-16 22:12:54

回答

11

調整高度比通過簡單地指定幾何「122」,你隱式地獲得自動的,相等大小的行和列噸。

要自定義佈局網格,您需要更具體一些。請參閱Matplotlib文檔中的「Customizing Location of Subplot Using GridSpec」。

36

參見電網規格教程:

http://matplotlib.sourceforge.net/users/gridspec.html

示例代碼:

import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 

f = plt.figure() 

gs = gridspec.GridSpec(1, 2,width_ratios=[2,1]) 

ax1 = plt.subplot(gs[0]) 
ax2 = plt.subplot(gs[1]) 

plt.show() 

也可以使用在GridSpec

的類似選項
+0

感謝您的提示。我沒有權限將matplotlib.gridspec導入爲gridspec。有另一種方法嗎? – thenickname 2011-02-22 21:24:49

+0

是否使用了不支持GridSpec的舊版matplotlib?你的問題還不清楚。 – JoshAdel 2011-02-22 22:45:43

+0

@thenickname:你可以做'輸入matplotlib'並調用'matplotlib.gridspac.GridSpec(1,2,等)' – heltonbiker 2011-12-07 12:25:13