2012-09-17 6 views
2

여러 소스의 데이터를 플로팅하고 multiple x axes이 필요합니다. 링크에 표시된 것과 같이 오프셋이 바람직합니다. x 축의 길이가 가변적이어서 같은 그림에 많은 그림을 칠할 수있게되었습니다.python/matplotlib - 기생 축 길이 지정

import matplotlib.pyplot as plt 
from mpl_toolkits.axes_grid1 import host_subplot 
import mpl_toolkits.axisartist as AA 
host = host_subplot(111, axes_class=AA.Axes,yscale='log') 
plt.subplots_adjust(bottom=0.25) 

par1 = host.twiny() 

offset = 60 

new_fixed_axis = par1.get_grid_helper().new_fixed_axis 
par1.axis['bottom'] = new_fixed_axis(loc='bottom', 
            axes=par1, 
            offset=(0, -60)) 

host.set_xlim(200, 350) 
host.set_ylim(1050, 100) 
par1.set_xlim(0, 1) 

host.set_xlabel('Temperature (K)') 
host.set_ylabel('Pressure (hPa)') 
par1.set_xlabel('Relative Humidity (%)') 

p1, = host.plot(T,P) 
p2, = host.plot(pT,P) 
p2, = par1.plot(RH,P) 

그래서 나는 축이 드롭 다운에 도착하지만, 내 인생을 위해, 예를 들어 청색 축 (같은 축이 실제로 수평으로 압축하는 얻는 방법을 알아낼 수 없습니다 : 내가 지금까지했던 것은 위 링크 된 그림 참조).

제 질문은 어떻게 수행 할 수 있습니까? 내가 도착하면

host = host_subplot(111, axes_class=AA.Axes,yscale='log') 
plt.subplots_adjust(bottom=0.25) 

par1 = host.twiny() 

new_fixed_axis = par1.get_grid_helper().new_fixed_axis 

cax1 = plt.axes(axisbg='none',frameon=False) 
cax1 = plt.add_axes(plt.get_position(), frameon=False) 
par1.axis['bottom'] = new_fixed_axis(loc='bottom', 
            axes=cax1, 
            offset=(0, -60)) 

:

cax1 = plt.add_axes(plt.get_position(), frameon=False) 

내 이전의 X/Y 축이 사라지고, 나는 왼쪽으로하고 여기에 Oz123

@


내가 가진 무엇 회색 화면에는 cax1 만 있습니다.

내 사과, 나는 matplotlib을 들었을 뿐이므로 나는 아직도 여기 초보자라고 생각한다.

답변

1

ax 개체를 사용하여 par1.axis['bottom']을 만들고 있으므로 실제 수행 할 수있는 작업은 매우 제한적입니다.
대신에 2 개 이상의 axes 인스턴스를 만들어야합니다. 그리고 그것들을 인물상에 올려 놓으십시오. 새로운 축 인스턴스를

cax1 = plt.axes (거짓 axisbg = '없음', frameon =)이 같이

를 추가

당신은 당신은 당신의 습도 규모의 크기의 미세 입자 제어 할 수 있습니다.

다음 줄 :

par1.axis['bottom'] = new_fixed_axis(loc='bottom', 
            axes=par1, 
            offset=(0, -60)) 

예를 들어 있어야한다 : IPython를 사용하여 신속 새로 만든 축 인스턴스를 제어 할 수있는 방법을 찾을 수

par1.axis['bottom'] = new_fixed_axis(loc='bottom', 
            axes=cax1, # custom axis number 1 
            offset=(0, -60)) 

참고.

In [38]: cax1.set_position? 
Type:  instancemethod 
String Form:<bound method AxesSubplot.set_position of <matplotlib.axes.AxesSubplot object at 0x2d7fb90>> 
File:  /usr/lib/pymodules/python2.7/matplotlib/axes.py 
Definition: cax1.set_position(self, pos, which='both') 
Docstring: 
Set the axes position with:: 

    pos = [left, bottom, width, height] 
:

In [38]: cax1.set_ #tab pressed 
cax1.set_adjustable   cax1.set_axis_bgcolor   cax1.set_frame_on    cax1.set_subplotspec   cax1.set_xticks 
cax1.set_agg_filter   cax1.set_axis_off    cax1.set_gid     cax1.set_title     cax1.set_ybound 
cax1.set_alpha     cax1.set_axis_on    
# many more options trimmed, but I think you might want to take a look in: 

새로 생성 된 인스턴스의 위치를 ​​제어