I have written a very simple code to have a scatter plot. I wondered to know how I can replace the figure by introducing a new y-axis
through a second function
, and updating the figure. in this example, I can plot based on the values for x, y1
. I want to know if I got new values such as y2
through another function, how to update the figure?
from tkinter import *
import matplotlib.pyplot as plt
root = Tk()
def plot():
x = [1,2,3,4,5,6,7,8,9]
y1 = [1,2,3,4,5,6,7,8,1]
plt.scatter(x, y1)
plt.title('Test')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
def update():
y2 = [1, 2, 3, 4, 5, 4, 3, 2, 1]
my_button1 = Button(root, text="plot", command=plot)
my_button1.pack()
my_button2 = Button(root, text="update", command=update)
my_button2.pack()
root.mainloop()