2014-11-05 108 views
3

我想要定位5個子圖,以便有三個頂部和兩個底部但彼此相鄰。當前的代碼靠攏,但我想最終的結果如下所示(忽略灰線):在Matplotlib中定位5個子圖

enter image description here

import matplotlib.pyplot as plt 

ax1 = plt.subplot(231) 
ax2 = plt.subplot(232) 
ax3 = plt.subplot(233) 
ax4 = plt.subplot(234) 
ax5 = plt.subplot(236) 

plt.show() 

Current rendering

回答

7

您可以使用合併單元格當您使用suplot2grid代替插曲。

import matplotlib.pyplot as plt 

ax1 = plt.subplot2grid(shape=(2,6), loc=(0,0), colspan=2) 
ax2 = plt.subplot2grid((2,6), (0,2), colspan=2) 
ax3 = plt.subplot2grid((2,6), (0,4), colspan=2) 
ax4 = plt.subplot2grid((2,6), (1,1), colspan=2) 
ax5 = plt.subplot2grid((2,6), (1,3), colspan=2) 

然後每副區需要是2周的cols寬,使得第二行中的副區可通過1列偏移。