2013-05-13 48 views
2

我試圖做類似顏色星圖:如何在不同的尺度上操縱多個x軸以相互對應?

B-V Diagram

我有一個包含確切相同數量的值的三個陣列。

x1 = B-V(-.5至2)

x2 =溫度。 (30000〜3000),並需要數比例

y1 =幅度(變化的基礎上的其他人)

x1x2,並y1陣列的所有聯繫,我想繪製在一起在散點圖中。

我的代碼:

#PLOTS 
x1 = bv_array  #B-V 
x2 = t_array  #Temperature 
y1 = Vavg_array  #Magnitude 
fig = plt.figure() 

ax1 = fig.add_subplot(111) 
#ax1.xlim(-.5,2) 
ax1.plot(x1, y1,'b--') 
ax2 = ax1.twiny() 
ax2.plot(x2, y1, 'go') 
ax2.set_xlabel('Temperature') 
ax2.invert_xaxis() 

#ax2.xscale('log') 
#plt.xscale('log') 
#plt.scatter(x,y) 

#plt.scatter(bv_array, Vavg_array, s = 1) 
plt.gca().invert_yaxis() 

plt.show() 

回答

1

如果我正確認識你,你就應該能夠挑上圖的右手邊,其中軸線應對準一個點,和matplotlib會從那裏拿走它。

ax1 = fig.add_subplot(111) 

ax1.xlim(-.5,2) # Set it in axis 1 coords 

ax1.plot(x1, y1,'b--') 
ax2 = ax1.twiny() 
ax2.plot(x2, y1, 'go') 
ax2.set_xlabel('Temperature') 
ax2.invert_xaxis() 

ax2.xlim(-2, 3) # Set it in axis 2 coords 

爲了確定點,制定出其軸(線性或對數)將需要更多的沿着x軸的「空間」,設置它的極限作爲其最大值,然後將其轉換成其他的座標空間軸將其用作其極限。