2014-10-08 137 views
0

我有两个问题关于我的数字下面张贴。我有一个数字,其中包含两种类型的数据,如下所示。最上面的子图(轴手柄= ax1)应该占用图的整个宽度(如已经完成的),以下子图(左列具有句柄ax2:ax6,右列具有句柄ax7:ax11)。我想要ax2:ax11子图共享x/y轴,如图所示(我将在后面清理标签等),但我也希望ax1和它下面的子图之间有空格,以便我可以看到ax1的x-tick标签和x轴标签(即在ax1和ax2/ax7之间有垂直空间)。问题1:谁能告诉我这是怎么完成的?Subplot特定间距和单轴标签

没有必要标记每个子图的(ax2:ax11)y轴。问题2:有人可以解释如何在图上放置一个y轴标签来代表ax2:ax11(ax1将拥有自己的y轴标签)?

我通过创建次要情节:

fig = figure(figsize=(5.5,7.5)) 
ax1 = subplot2grid(shape=(6,2),loc=(0,0),rowspan=1,colspan=2) # dSCD vs SZA 
ax2 = subplot2grid(shape=(6,2),loc=(1,0),rowspan=1,colspan=1) # resid @ SZA==90am 
ax3 = subplot2grid(shape=(6,2),loc=(2,0),rowspan=1,colspan=1) # resid @ SZA==91am 
ax4 = subplot2grid(shape=(6,2),loc=(3,0),rowspan=1,colspan=1) # resid @ SZA==92am 
ax5 = subplot2grid(shape=(6,2),loc=(4,0),rowspan=1,colspan=1) # resid @ SZA==93am 
ax6 = subplot2grid(shape=(6,2),loc=(5,0),rowspan=1,colspan=1) # resid @ SZA==94am 

ax7 = subplot2grid(shape=(6,2),loc=(1,1),rowspan=1,colspan=1) # resid @ SZA==90pm 
ax8 = subplot2grid(shape=(6,2),loc=(2,1),rowspan=1,colspan=1) # resid @ SZA==91pm 
ax9 = subplot2grid(shape=(6,2),loc=(3,1),rowspan=1,colspan=1) # resid @ SZA==92pm 
ax10 = subplot2grid(shape=(6,2),loc=(4,1),rowspan=1,colspan=1) # resid @ SZA==93pm 
ax11 = subplot2grid(shape=(6,2),loc=(5,1),rowspan=1,colspan=1) # resid @ SZA==93pm 

fig.subplots_adjust(hspace=0,wspace=0,top=0.95) 
ax1.set_xlabel('Text Text Text',fontsize=8) 

enter image description here

回答

2

您可以使用GridSpec直接创建两套轴,一个在顶部,一个在底部,并把它们之间的空间。要为所有轴创建y标签,请使用图text

import matplotlib.pyplot as plt 
from matplotlib.gridspec import GridSpec 

fig = plt.figure(figsize=(5.5,7.5)) 

gs1 = GridSpec(1, 1) 
gs1.update(left=0.05, right=0.95, top=0.95, bottom=0.85, wspace=0.05) 
ax1 = plt.subplot(gs1[0]) 
ax1.set_xticks([]) 
ax1.set_yticks([]) 

gs2 = GridSpec(5, 2) 
gs2.update(top=0.75, hspace=0.05) 

for i in gs2: 
    ax = plt.subplot(i) 
    ax.set_xticks([]) 
    ax.set_yticks([]) 

ax1.set_xlabel('Text Text Text',fontsize=8) 
fig.text(0.03,0.45,'some label',rotation='vertical') 

plt.show() 

GridSpec with shared y label

+0

这完美地工作。对不起,我没有早点回复你! – tnknepp 2014-12-11 19:42:48