Could someone please shed some light on this?
This code is supposed to print out the event details on a mouse button press. If I connect the button_press_event
slot to on_button_press
(outside the class), the code works as expected. If I instead use the class method self.on_button_press
, nothing is printed out. Why is that?
import matplotlib.pyplot as pltclass Modifier: def __init__(self, initial_line): self.initial_line = initial_line self.ax = initial_line.axes canvas = self.ax.figure.canvas cid = canvas.mpl_connect('button_press_event', self.on_button_press) def on_button_press(self, event): print(event)def on_button_press(event): print(event)fig, ax = plt.subplots()ax.set_aspect('equal')initial = ax.plot([1,2,3], [4,5,6], color='b', lw=1, clip_on=False)Modifier(initial[0])plt.show()