2017-04-26 1 views
0

동일한 x 축을 가진 여러 개의 플롯이 있습니다. 나는 그들을 보고서에 쌓아 놓고 모든 것이 정렬되게하고 싶다. 그러나 matplotlib는 y tick 레이블 길이에 따라 약간 크기가 조정 된 것으로 보입니다.플롯 영역을 고정하기 위해 matplotlib를 강제로 만듭니다.

내가 저장 한 PDF 캔버스에 비례하여 플롯 영역과 위치가 플롯간에 동일하게 유지되도록 할 수 있습니까?

import numpy as np 
import matplotlib.pyplot as plt 
xs=np.arange(0.,2.,0.00001) 
ys1=np.sin(xs*10.) #makes the long yticklabels 
ys2=10.*np.sin(xs*10.)+10. #makes the short yticklabels 

fig=plt.figure() #this plot ends up shifted right on the canvas 
plt.plot(xs,ys1,linewidth=2.0) 
plt.xlabel('x') 
plt.ylabel('y') 

fig=plt.figure() #this plot ends up further left on the canvas 
plt.plot(xs,ys2,linewidth=2.0) 
plt.xlabel('x') 
plt.ylabel('y') 
+0

같은 그림에서 서브 플로트로 그릴 수 있습니까? – DavidG

+0

두 경우 모두 플롯의 크기가 동일합니다. 또한 축의 크기도 같습니다. 당신이 요구하는 것이 명확하지 않습니다. – ImportanceOfBeingErnest

답변

2

귀하의 문제는 그러나이 줄거리의 축과 그림 크기가이 만들어 서로

import numpy as np 
import matplotlib.pyplot as plt 

xs=np.arange(0.,2.,0.00001) 
ys1=np.sin(xs*10.) #makes the long yticklabels 
ys2=10.*np.sin(xs*10.)+10. #makes the short yticklabels 

fig, (ax1, ax2) = plt.subplots(2, 1) 
ax1.plot(xs,ys1,linewidth=2.0) 
ax1.set_xlabel('x') 
ax1.set_ylabel('y') 

ax2.plot(xs,ys2,linewidth=2.0) 
ax2.set_xlabel('x') 
ax2.set_ylabel('y') 

plt.subplots_adjust(hspace=0.3) # adjust spacing between plots  
plt.show() 

와 alligned됩니다 gaurantee해야 같은 그림과 줄거리로 음모를 꾸미고, 조금 불분명하다 다음 그림 :

enter image description here

0

같은 x 축과 줄거리를 사용하여 트릭을 할해야합니다.

을 사용하면 하위 그림을 만들 수 있습니다. sharex의 장점은 1 개의 서브 플롯에서 확대/축소 또는 이동이 공유 축이있는 모든 서브 플로트에서 자동 업데이트된다는 것입니다.

import numpy as np 
import matplotlib.pyplot as plt 
xs = np.arange(0., 2., 0.00001) 
ys1 = np.sin(xs * 10.) # makes the long yticklabels 
ys2 = 10. * np.sin(xs * 10.) + 10. # makes the short yticklabels 

fig, (ax1, ax2) = plt.subplots(2, sharex=True) 
ax1.plot(xs, ys1, linewidth=2.0) 
ax1.xlabel('x') 
ax1.ylabel('y') 

ax2.plot(xs, ys2, linewidth=2.0) 
ax2.xlabel('x') 
ax2.ylabel('y') 
plt.show() 
관련 문제