2014-10-02 3 views
0

matplotlib에서 두 개의 별개의 X 축을 가질 수 있는지 궁금해했지만 그래프의 반대쪽에 있지는 않습니다. 대신, 서로 옆에 놓을 수 있습니까?두 개의 낮은 X 축 matplot lib

답변

2

이게 당신이 찾고 있는게 있나요?

Two x-axes on the bottom.

from mpl_toolkits.axes_grid1 import host_subplot 
import mpl_toolkits.axisartist as AA 
import matplotlib.pyplot as plt 


host = host_subplot(111, axes_class=AA.Axes) 
plt.subplots_adjust(bottom=0.2) 

par2 = host.twiny() 

offset = -40 
new_fixed_axis = par2.get_grid_helper().new_fixed_axis 
par2.axis["bottom"] = new_fixed_axis(loc="bottom", 
            axes=par2, 
            offset=(0, offset)) 

par2.axis["top"].toggle(all=False) 

host.set_xlim(0, 2) 
host.set_ylim(0, 2) 

host.set_ylabel("Distance") 
host.set_xlabel("Density") 
par2.set_xlabel("Velocity") 

p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density") 
p3, = par2.plot([50, 30, 15], [0, 1, 2], label="Velocity") 

par2.set_xlim(1, 65) 

host.legend() 

host.axis["bottom"].label.set_color(p1.get_color()) 
par2.axis["bottom"].label.set_color(p3.get_color()) 
+0

감사합니다,하지만 난 X 축이 수평으로 서로 옆에 있습니다 있도록이 작업을 수행 할 수있을 것입니다 방법? – modred

+0

'옆에'라고 말하면 '위와 아래'를 의미합니까? – farenorth

+0

예제 코드 (전체 내용)를 제공하고 내가 원하는 것을하지 않는 이유를 설명하면 도움이 될 수 있습니다. – farenorth