I'd like to be able to click on the two buttons generated in the IPython GUI and then generate a total of 6 points on the same graph. However, right now clicking the two buttons does not create the 6 points, and only creates the graph made by the first button to be clicked. What am I doing wrong?
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from ipywidgets.widgets import Button
from IPython.display import display
class Test(object):
def __init__(self):
self.figure = plt.figure()
self.ax = self.figure.gca()
self.button = Button(description = "Draw new points.")
display(self.button)
self.button.on_click(self.button_clicked)
self.button2 = Button(description = "Draw more points.")
display(self.button2)
self.button2.on_click(self.button_clicked2)
def button_clicked(self, event):
self.ax.scatter([1,2,8], [6,5,4])
self.figure.canvas.draw()
plt.show()
def button_clicked2(self, event):
self.ax.scatter([1,0,5], [3,8,3])
self.figure.canvas.draw()
plt.show()
test = Test()