2013-05-08 84 views
1

如何去除漸近線?pylab plot顯示漸近線

import numpy as np 

e = 1.26 
beta = .705 * np.pi 
rph = 7000 
re = 6378 

def r(nuh): 
    return rph * (1 + e)/(1 + e * np.cos(nuh + beta)) 


theta = np.linspace(-np.pi, np.pi, 50000) 

fig2 = pylab.figure() 
ax2 = fig2.add_subplot(111) 
ax2.plot(r(theta) * np.cos(theta), r(theta) * np.sin(theta)) 
ax2.plot(rph * np.cos(theta), rph * np.sin(theta), 'r') 
# adding the Earth                 
earth2 = pylab.Circle((0, 0), radius = re, color = 'b') 
ax2.add_patch(earth2) 
pylab.xlim((-50000, 100000)) 
pylab.ylim((-50000, 100000)) 
pylab.show() 

with asymptotes

+0

什麼是漸近線?另外,你還沒有定義're'。 – askewchan 2013-05-08 17:45:41

+0

@askewchan漸近線是繪製雙曲線時繪製的多餘直線。現在定義re。 – dustin 2013-05-08 17:51:19

回答

3

你可以see here,發散點設置爲np.nan將導致他們不被繪製。

在你的問題中,它是r(theta)這是分歧。以通常的方式定義rtheta,但是接下來,要將r(theta)的極值設置爲np.nan

要做到這一點,讓一個數組第一,那麼它的極值改變np.nan

rt = r(theta) 
ext = [np.argmin(rt), np.argmax(rt)] 
rt[ext] = np.nan 

現在,一定要與修改後的rt陣列繪製不是原來的功能:

ax2.plot(rt * np.cos(theta), rt * np.sin(theta)) 

No asymptotes :)