不一致有点令人讨厌,但是要更新圆的位置,请设置
circ.center = new_x, new_y。
作为一个简单的(不可拖动的)示例:
import matplotlib.pyplot as pltfrom matplotlib.patches import Circleclass InteractiveCircle(object): def __init__(self): self.fig, self.ax = plt.subplots() self.ax.axis('equal') self.circ = Circle((0.5, 0.5), 0.1) self.ax.add_artist(self.circ) self.ax.set_title('Click to move the circle') self.fig.canvas.mpl_connect('button_press_event', self.on_click) def on_click(self, event): if event.inaxes is None: return self.circ.center = event.xdata, event.ydata self.fig.canvas.draw() def show(self): plt.show()InteractiveCircle().show()


