I am trying to embed a matplotlib FuncAnimation
live updating plot to a tkinter
window but I am getting 2 plots (one inside the tkinter window and other as an extra matplotlib plot) as shown below.
But I just need one inside the tkinter window.
This is the part of the code which generates the GUI.
Main Class
from tkinter import Tk
import VisualizationPage1
class VisualizationGui(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
....other code
frame = VisualizationPage1.VisualizationPage1(self.global_container, self)
frame.grid(row=0, column=0, sticky=NSEW)
frame.tkraise()
frame.set_ui()
if __name__ == "__main__":
app = VisualizationGui()
app.mainloop()
VisualizationPage1 Class
class VisualizationPage1():
def __init__(self, parent, controller):
super().__init__(parent, controller)
# Define self.body_sublabelframe2 and other frames
plotting_function()
def plotting_function(self):
x_val = []
y_val = []
figure1 = plt.figure(figsize=(8, 8), linewidth=5, edgecolor="#04253a", dpi=35)
ax1 = figure1.add_subplot(111)
canvas_1 = FigureCanvasTkAgg(figure1, self.body_sublabelframe2)
canvas_1.get_tk_widget().grid(row=0, column=0)
ax1.legend(["Some Legend"])
ax1.set_xlabel("X Label")
ax1.set_ylabel("Y Label")
ax1.set_title("Plot Title")
def animate(i):
x_val.append(len(x_val))
y_val.append(2 ** len(y_val))
ax1.cla()
ax1.plot(x_val, y_val)
ani1 = FuncAnimation(figure1, animate, interval=100)
plt.show()
The data is just some dummy data which I need to replace with some live data which is why I need this live updating feature in matplotlib.