2015-07-28 148 views
1

我有一个matplotlib图,这实际上是两个不同高度的子图,看起来像一个单独的不连贯图。分享Y轴标签

enter image description here

我已经这样做了使用Gridspec:

outer = gridspec.GridSpec(2, 1, height_ratios=[1,3]) 
gs1 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec = outer[0]) 
ax1 = plt.subplot(gs1[0]) 
ax1.plot(no_rot,max_sd,'k*') 
plt.ylabel('Y Axis Label') 

gs2 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec = outer[1]) 
ax2 = plt.subplot(gs2[0]) 
ax2.plot(no_rot,max_sd,'k*') 
plt.xlabel('X Axis Label') 
plt.ylabel('Y Axis Label') 

我现在只想有一个共享的,集中式的Y轴的标签,但我不知道如何做到这一点。

回答

1

你可以尝试存储与参考标签:

yaxis_label = plt.ylabel('My Y-axis') 

然后改变相对单位,例如它的位置

yaxis_label.set_position((-0.05,0.5)) 

由于您有两个子图,因此您可能需要调整相对(x,y)以正确定位。

或者,把你的次要情节明确的数字,放置一个文本标签相对于图中的Y轴坐标:

ax.text(0.05, 0.5, "My y-axis", transform=f.transFigure, rotation='vertical', 
     verticalalignment='center')