나는 자동으로 라벨을 정렬 위해 작성한 함수이지만, 대화 형, 스크립트에서 작동하지 않는 것 : 귀하의 경우를 들어이 같은 일이 될 것입니다.
def align_labels(axes_list,axis='y',align=None):
if align is None:
align = 'l' if axis == 'y' else 'b'
yx,xy = [],[]
for ax in axes_list:
yx.append(ax.yaxis.label.get_position()[0])
xy.append(ax.xaxis.label.get_position()[1])
if axis == 'x':
if align in ('t','top'):
lim = max(xy)
elif align in ('b','bottom'):
lim = min(xy)
else:
if align in ('l','left'):
lim = min(yx)
elif align in ('r','right'):
lim = max(yx)
if align in ('t','b','top','bottom'):
for ax in axes_list:
t = ax.xaxis.label.get_transform()
x,y = ax.xaxis.label.get_position()
ax.xaxis.set_label_coords(x,lim,t)
else:
for ax in axes_list:
t = ax.yaxis.label.get_transform()
x,y = ax.yaxis.label.get_position()
ax.yaxis.set_label_coords(lim,y,t)
그리고 예 :
fig,ax = subplots(2,2)
ax00,ax01 = ax[0]
ax10,ax11 = ax[1]
ax00.set_ylim(1000,5000)
ax00.set_ylabel('top')
ax10.set_ylabel('bottom')
ax10.set_xlabel('left')
ax11.set_xlabel('right')
ax11.xaxis.axis_date()
fig.autofmt_xdate()
#we have to call draw() so that matplotlib will figure out the automatic positions
fig.canvas.draw()
align_labels(ax[:,0],'y')
align_labels(ax[1],'x')
여기에 설명 된 내용은 http://matplotlib.org/faq/howto_faq입니다.html # align-my-ylabels-across-multiple-subplots –