2016-11-27 3 views
1
바로 옆에 다른 차 플롯을 배치

O 오전 나는 3 줄거리 하기 matplotlib의 gridspec - 여러 줄거리

import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 
gs1 = gridspec.GridSpec(3,2) 
ax1 = plt.subplot(gs1[0, :]) 
ax2 = plt.subplot(gs1[1, :],sharex=ax1) 
ax3 = plt.subplot(gs1[2, :],sharex=ax1) 
plt.setp(ax1.get_xticklabels(), visible=False) 
plt.setp(ax2.get_xticklabels(), visible=False) 
plt.show() 

enter image description here 어떻게

의 오른쪽에, 입방 모양의 또 다른 음모를 배치하는 방법을 해결하기 위해 할 수있는 노력 gridspec을 사용하는 옆의 세 줄에 걸쳐 다른 줄을 배치 하시겠습니까?

답변

2

이미 두 개의 열로 세분하여 gridspec에 대한 적절한 분할을 정의했습니다. 왼쪽 축이 첫 번째 열 (아래 변경 참조)을 사용하고 "세제곱"(가로 세로 비율 1)로 간주되는 축이 gridspec의 오른쪽 열을 사용하도록 지정합니다.

import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 
gs1 = gridspec.GridSpec(3,2) 
ax1 = plt.subplot(gs1[0, 0]) 
ax2 = plt.subplot(gs1[1, 0],sharex=ax1) 
ax3 = plt.subplot(gs1[2, 0],sharex=ax1) 
ax4 = plt.subplot(gs1[:, 1]) # NEW 
ax4.set_aspect('equal', adjustable='box') # NEW 
plt.setp(ax1.get_xticklabels(), visible=False) 
plt.setp(ax2.get_xticklabels(), visible=False) 
plt.show() 

gridspec with two columns

또는, 그렇게 같이 각 gridspec의 (상대적) 위치를 제 gridspec 정의하고 업데이트 할 수 :

import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 
gs1 = gridspec.GridSpec(3,2) 
gs1.update(left=0.05, right=0.48, wspace=0.05) 
ax1 = plt.subplot(gs1[0, :]) 
ax2 = plt.subplot(gs1[1, :],sharex=ax1) 
ax3 = plt.subplot(gs1[2, :],sharex=ax1) 

gs2 = gridspec.GridSpec(1, 1) 
gs2.update(left=0.55, right=0.98, hspace=0.05) 
ax4 = plt.subplot(gs2[0,0]) 
#ax4.set_aspect('equal', adjustable='box') 
plt.setp(ax1.get_xticklabels(), visible=False) 
plt.setp(ax2.get_xticklabels(), visible=False) 
plt.show() 

를 I는 동일한 형태를 얻을 수있는 코드를 주석 비율을 기본값으로 강조 표시하여 ax4으로 설정하면 사용 가능한 전체 공간이 채워집니다.

alternative gridspec

관련 문제