2013-07-25 1 views
3
에 내가하기 matplotlib 페이지의 예에서와 같이 suplot2grid 사용하고

subplot2grid를 사용하여 로컬 타이틀을 만들 수있는 방법이 있나요 :파이썬

ax1 = plt.subplot2grid((3,3), (0,0), colspan=3) 
ax2 = plt.subplot2grid((3,3), (1,0), colspan=2) 
ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2) 
ax4 = plt.subplot2grid((3,3), (2, 0)) 
ax5 = plt.subplot2grid((3,3), (2, 1)) 
plt.suptitle("subplot2grid") 

enter image description here

로컬 자막을 만들 수있는 방법이 있나요 그것의 위에 세계적인 것 대신에, ax1의 아래에?

감사

답변

6

당신은 축의 set_title() 메소드를 사용하여 각각의 서브 플롯에 타이틀을 추가 할 수 있습니다. 각 제목은 여전히 ​​축 위에 표시됩니다. 축 아래에 텍스트를 원하면 set_xlabel을 사용할 수 있습니다. 예를 들어 :

import pylab as plt 
ax1 = plt.subplot2grid((3,3), (0,0), colspan=3) 
ax2 = plt.subplot2grid((3,3), (1,0), colspan=2) 
ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2) 
ax4 = plt.subplot2grid((3,3), (2, 0)) 
ax5 = plt.subplot2grid((3,3), (2, 1)) 

# add titles to subplots 
ax2.set_title('plot 2') 
ax3.set_title('plot 3') 

# add x-label to subplot 
ax1.set_xlabel('plot 1 x-label') 

# add y-label to subplot 
ax1.set_ylabel('y-label') 

plt.tight_layout() 
plt.show() 

enter image description here

당신은 또한이 같은 새로운 타이틀을 추가 figtext를 사용할 수 있습니다

# add Text 
pos = ax1.get_position() 
x = pos.x0 + 0.35 
y = pos.y0 
plt.figtext(x,y,'new title') 
plt.tight_layout() 
plt.show() 
+0

완성도를 들어,'set_ylabel'을 추가해야합니다) 확인 – tacaswell

+0

을. Y- 라벨이 추가되었습니다! – Molly

+0

그래, 나도 알아,하지만 나는 각 새로운 음모에 대한 특정 음모가 아니라 ax1 아래 음모를 encompases 또 다른 글로벌 부제를 원한다. –