Python底图移除伟大的ci

2024-07-04 05:51:29 发布

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

我设置了一个回调函数,当你点击其中一个点时,它会连接地图上的两个相应点。我的问题是我似乎不能删除连接他们的线路。基本上,每次单击标记时都会调用下面的函数。我需要它来删除旧的大圆并绘制新的大圆。相反,它只是继续创建新行,而不是删除旧行。您可以忽略if语句,因为它们按预期工作。思想?你知道吗

def mapPair(self,localLat,localLon,remoteLat, remoteLon):
    if self.connectingLine != None:
        self.connectingLine.remove() # <--doesn't work

    if localLat != "unknown" and self.currentLocalItem is None:
        self.currentLocalItem, = self.map.plot(localLon, localLat, 'bo', markersize=15, color='g', label="Local")
    elif localLat!= "unknown" and self.currentLocalItem is not None:
        self.currentLocalItem.set_ydata(localLat)
        self.currentLocalItem.set_xdata(localLon)

    self.connectingLine = self.map.drawgreatcircle(localLon, localLat, remoteLon, remoteLat, lw=3)

    self.fig.canvas.draw()

Tags: and函数selfnonemapifisunknown
1条回答
网友
1楼 · 发布于 2024-07-04 05:51:29

嗯,我不知道为什么会发生这种情况(或者它是否应该发生),但我指定的时间自连接线我得到的是一个列表而不是一个对象。我不知道怎么解决这个问题,所以这是我的工作

def mapPair(self,localLat,localLon,remoteLat, remoteLon):
    if self.connectingLine != None:
        for x in self.connectingLine:
            x.remove()

    if localLat != "unknown" and self.currentLocalItem is None:
        self.currentLocalItem, = self.map.plot(localLon, localLat, 'bo', markersize=15, color='g', label="Local")
    elif localLat!= "unknown" and self.currentLocalItem is not None:
        self.currentLocalItem.set_ydata(localLat)
        self.currentLocalItem.set_xdata(localLon)

    self.connectingLine = self.map.drawgreatcircle(localLon, localLat, remoteLon, remoteLat, lw=3)

相关问题 更多 >

    热门问题