I am trying to get a live matplotlib graph working in Tkinter while using a class structure. I am using the code from this stackoverflow question which successfully runs a matplotlib graph in Tkinter(does not use class structure). Every time I try to run the code I altered I am given a
TypeError: __init__ takes exactly 2 arguments (1 given)
I know this TypeError type question has been asked before. I tried to use this but the answer provided did not solve my problem.
The line of code that seems to be the problem is:
ani = animation.FuncAnimation(Window().fig, Window().animate(), interval=1000, blit=Fals
I have tried altering how I call fig and animate but nothing seems to work.
import Tkinter as Tk
from matplotlib import pyplot as plt
import matplotlib.animation as animation
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
xar = []
yar = []
class Window:
def __init__(self,master):
frame = Tk.Frame(master)
fig = plt.figure(figsize=(14, 4.5), dpi=100)
self.ax = fig.add_subplot(1,1,1)
self.ax.set_ylim(0, 100)
self.line, = self.ax.plot(xar, yar)
self.canvas = FigureCanvasTkAgg(fig,master=master)
self.canvas.show()
self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
frame.pack()
def animate(self,i):
yar.append(99-i)
xar.append(i)
self.line.set_data(xar, yar)
self.ax.set_xlim(0, i+1)
root = Tk.Tk()
ani = animation.FuncAnimation(Window().fig, Window().animate(),interval=1000, blit=False)
app = Window(root)
root.mainloop()