如何在ipython中获得不同的点

2024-10-02 00:28:07 发布

您现在位置:Python中文网/ 问答频道 /正文

plt.plot(jd1,spd1)
plt.plot(jd1,spd1,marker="o",markerfacecolor="r",linestyle='None')
plt.show()

print 'click on any obviously bad points and then press the enter key.'
badpoints=ginput(n=0)

index_badpoints=[]
badpoints_num=len(badpoints)
for i in range(len(badpoints)):
     index_badpoints.append(int(np.interp(badpoints[i][0],
                                          yeardays,
                                          range(len(yeardays)))))

print index_badpoints #always[107,107,107...]

问题是无论我点击哪一个点,我只能得到指数是107的点。 有人能帮我解决这个问题吗?你知道吗


Tags: noneindexlenplotshowrangepltmarker
1条回答
网友
1楼 · 发布于 2024-10-02 00:28:07

我无法测试您的版本,但我可以向您展示如何解决此问题:

badpoints = np.array(ginput(n=0))
index_badpoints = np.argmin(abs(np.subtract(badpoints[:,0],yeardays)),axis=1)

这将计算沿x轴从yeardays到badpoints的距离,并返回最近的索引。你知道吗

相关问题 更多 >

    热门问题