2013-05-08 85 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 :)