Я новичок в Python.Я хочу обновить отображаемый график после нажатия кнопки.Например, я хочу изменить цвет.
Спасибо за вашу помощь!
from tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class App(Frame):
def change_to_blue(self):
# todo self.ax.plot.color = 'blue' ????
# todo self.fig.update() ???
print('graph should be blue now instead of red')
def __init__(self, master):
Frame.__init__(self, master)
Button(master, text="Switch Color to blue", command=lambda: self.change_to_blue()).pack()
self.fig = Figure(figsize=(6, 6))
self.ax = self.fig.add_subplot(111)
self.ax.plot(x, y, color='red')
self.canvas = FigureCanvasTkAgg(self.fig, master=master)
self.canvas.draw()
self.canvas.get_tk_widget().pack()
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
root = Tk()
app = App(root)
root.mainloop()