I know there are other people asking this question in their specific context, but none of those answers have gotten me closer to figuring this out. I am trying to use a class in matplotlib to add plots to a figure.
I'm trying to get the class to take as an argument a Line2D object and interpret it a bit - this is working. The class also registers a callback to mouse click events on the plot window - this is also working. Here's what's not working:
fig, ax = plt.subplots()
series, = ax.plot(x_data, y_data)
classthing = MyClass(series)
plt.show()
And here is the class that is being instanced:
class MyClass:
def __init__(self, series):
self.series = series
self.cid = series.figure.canvas.mpl_connect('button_press_event', self)
def __call__(self, event):
self.series.figure.plot([xdata], [ydata])
self.series.figure.canvas.draw()
On mouse click I want to add a plot to the figure that I clicked on. This is really similar to the example here: https://matplotlib.org/users/event_handling.html
This code successfully creates the plot and the object, but obviously I'm not calling the plot() method from the correct reference since I get the title error on the second to last line. How can I reference the plot object properly given only the Line2D object that is in it? I am not anywhere near competent with OOP.
Thanks in advance for your help.