del_between=raw_input('Do you want to delete all the points between two points? input "N" or "Y"')
if del_between=="N" or del_between=="n":
    print "You have choosen NOT to delete all the points between two points."
if del_between=="Y" or del_between=="y" :
    print "Please click the first bad point and the last bad point to choose the range of the bad points"
    between_badpoints=ginput(n=2)
    print between_badpoints
    index_between_badpoints=[]
    for i in range(len(between_badpoints)):
         index_between_badpoints.append(int(np.interp(between_badpoints[i][0],jd2,range(len(jd2)))))
    print index_between_badpoints
    index_betweens=[]
    for i in range(sorted(index_between_badpoints)[0],sorted(index_between_badpoints)[1]+1):
         index_betweens.append(i)
    print index_betweens
    for i in index_betweens[::-1]:
         del lat[i],lon[i],time[i],yeardays[i],depth[i],temp[i]


该程序试图删除收集的两个点之间的所有点。问题是当我尝试运行该程序时,它将显示分段错误。

当我单击以选择点时,它将引发异常“分段错误”,因此我认为问题可能集中在“ between_badpoints = ginput(n = 2)”这一行上。但是我不明白为什么这是错误的。

(我在同一程序中使用了此“ ginput”命令,它运行良好,然后删除了ginput变量,并再次使用,就像这样,它不起作用。)

最佳答案

我已经弄清楚了。这是我第二次在该程序中使用ginput,但是我还没有创建新的图形。在添加'fig = plt.figure()'行之后,每一步都进行得很好。可能是每个图形只能使用ginput一次。

07-26 05:56