在我的情况下,我只想每次拖动一个点.但是,由于两个点重叠很重,拖动一个点会导致拖动另一个点.我怎么才能拖动上面的点?谢谢!
from pylab import *
from scipy import *
import matplotlib.pyplot as plt
import matplotlib.patches as patches
class DraggablePoint:
def __init__(self, p):
self.point = p
self.press = None
def connect(self):
self.cidpress = self.point.figure.canvas.mpl_connect('button_press_event', self.button_press_event)
self.cidrelease = self.point.figure.canvas.mpl_connect('button_release_event', self.button_release_event)
self.cidmotion = self.point.figure.canvas.mpl_connect('motion_notify_event', self.motion_notify_event)
def disconnect(self):
'disconnect all the stored connection ids'
self.point.figure.canvas.mpl_disconnect(self.cidpress)
self.point.figure.canvas.mpl_disconnect(self.cidrelease)
self.point.figure.canvas.mpl_disconnect(self.cidmotion)
def button_press_event(self,event):
if event.inaxes != self.point.axes:
return
contains = self.point.contains(event)[0]
if not contains: return
self.press = self.point.center, event.xdata, event.ydata
def button_release_event(self,event):
self.press = None
self.point.figure.canvas.draw()
def motion_notify_event(self, …Run Code Online (Sandbox Code Playgroud)