2016-11-20 9 views
1

同じ図で2つの異なる関数をプロットしたいとします。しかし、彼らは彼らのx軸に異なるスケールを使用したい。 1つの目盛りはxの値を表示するだけで、他のものは最後に秒を表示する必要があります。同じ図の2つの関数を2つのx軸に異なる縮尺でプロットする

は、今私は、私は申し訳ありませんが、この

k=5 
fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax1.set_xlabel(r"values of x") #adds description to scale on bottom 
ax2 = ax1.twiny()  #adds the seconds scale on top 

x = np.arange(0.1, 1.5, 0.1) #values of x for function are in range 
y = k*(np.power(x,(k-1))) * np.exp(-(np.power(x,(k-1)))) #that is the function I want to draw 
ax1.plot(x,y)  #draw function 
tx = x 
ty = x*7 
ax2.plot(x,x*7) 

ax2.set_xlabel(r"time in seconds") 
ax2.set_xlim(1484)  #set limit of time 
ax2.invert_xaxis()  #invert it so that it works like we want to 
ax1.set_xlim(0.1,1.4)  #set limit for the x axis so that it doesn't skale on its own. 
plt.show() 

持っているが、私は適切にコードを挿入することができませんでした。 ax2関数は今やちょうどダミーです。私はそれを見ることができるだけでなく、最後にax2のスケールを私の時間枠に変えたいと思っています。

ご協力いただければ幸いです!

答えて

1

私はあなたのコードはAX2用

あなたのダミー関数:-P動作しないことを確認していないが、十分ではないですが、私はそれを見ることができるようにax2.plot(x*1000,x*50)でそれを置き換えます。

k=5 
fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax1.set_xlabel(r"values of x") #adds description to scale on bottom 
ax2 = ax1.twiny()  #adds the seconds scale on top 

x = np.arange(0.1, 1.5, 0.1) #values of x for function are in range 
y = k*(np.power(x,(k-1))) * np.exp(-(np.power(x,(k-1)))) #that is the function I want to draw 
ax1.plot(x,y)  #draw function 
tx = x 
ty = x*7 


ax2.set_xlabel(r"time in seconds") 
ax2.set_xlim(1484)  #set limit of time 
ax2.invert_xaxis()  #invert it so that it works like we want to 
ax2.plot(x*1000,x*50) 
ax1.set_xlim(0.1,1.4)  #set limit for the x axis so that it doesn't skale on its own. 
plt.show() 

います:

enter image description here

1

を2番目のプロットが左Y軸の後ろに隠れている

そして、私は再スケーリング後のプロットを行います。あなたは太い線および/またはマーカーを使用している場合、それを見ることができるようになります:

ax2.plot(x,x*7, '-o', lw=5) 

A plot

あなたにもax2のx制限を変更することができますが、あなたはそれを作るためにあなたの方法から出て行きましたそれがそうであるように私はあなたがそれが欲しいのとまったく同じだと思います。

関連する問題