2015-07-28 170 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')