我试图在第三次点击图表后删除axvspan()函数。
到目前为止,这是我的代码:
def shaded_region(self, event):
if event.button == 1 and ViewWidget.click == 0:
ViewWidget.click +=1
ViewWidget.xx1 = event.xdata
self.cid2 = self.figure_canvas.mpl_connect("motion_notify_event", self.mouseCoordsInMotion)
def mouseCoordsInMotion(self, event):
X1 = ViewWidget.xx1
X2 = event.xdata
self.aspan = self.axes.axvspan(X1,X2, alpha = 0.3, color = "cyan")
self.figure_canvas.draw_idle()
self.cid3 = self.figure_canvas.mpl_connect('button_press_event', self.selectedRegion)
def selectedRegion(self, event):
ViewWidget.click += 1
if event.button == 1 and ViewWidget.click == 2:
print "Conectado a selectedRegion"
self.figure_canvas.mpl_disconnect(self.cid1)
self.figure_canvas.mpl_disconnect(self.cid2)
ViewWidget.click = 3
X1 = ViewWidget.xx1
ViewWidget.xx2 = event.xdata
X2 = ViewWidget.xx2
self.aspan = self.axes.axvspan(X1,X2, alpha = 0.3, color = "cyan")
return ViewWidget.xx1, ViewWidget.xx2, ViewWidget.click
else:
ViewWidget.click = 3
self.figure_canvas.mpl_disconnect(self.cid3)
def erase_selection(self, event):
if event.button == 1 and ViewWidget.click == 3:
ViewWidget.click = 0
self.aspan.remove()
self.figure_canvas.draw_idle()
所以,使用方法shaded_region
当我点击一次时,我开始从鼠标的坐标绘图。然后我再次点击停止绘图,当我想删除我用第三次点击绘制的内容时,它不起作用。
我怎样才能做到这一点?希望你能帮帮我。