pylab图显示渐近线

时间:2013-05-08 15:59:00

标签: python numpy matplotlib 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

1 个答案:

答案 0 :(得分: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 :)