How to add a Matplotlib Graph to Tkinter Window in Python 3 - Tkinter tutorial Python 3.4 p. 6
Why Stack Overflow recommends it
Stack Overflow users link it as the walkthrough for embedding Matplotlib graphs in Tkinter, and many askers say their code was adapted from it.
Recommended by 1 people across 1 different months, 2016 to 2020.
What it is
Part 6 of sentdex's Tkinter tutorial series for Python 3.4. It shows how to embed a Matplotlib figure inside a Tkinter window using FigureCanvasTkAgg and the navigation toolbar, building on the multi-page app from earlier episodes.
What people said
Recommends Pablo Díaz · 2019-08 · Stack Overflow · on “Integrating matlab graphs to tkinter (showing graphs on different pages) with csv”
To use matplotlib, you need use the backend. There's a video in English by Sentdex to use the backend. Plotting images in tkinter is different. Video [this video] Also in the video Sentdex use for Python3.X use from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk instead of from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg and maybe these libraries you will requier later import tkinter as tk import matplotlib import matplotlib.pyplot as plt import matplotlib.mlab as mlab from matplotlib.figure import Figure Example code to plot: ax = self.figure.add_subplot(111) #new_data contains the data. In this example code, nothing new_d
Cites Julian · 2016-08 · Stack Overflow · on “"python.exe has stopped working" crash, FigureCanvasTkAgg.show()”
I am running an Anaconda environment with python 3.4, on Windows 7 canvas.show() is causing my python code to crash: EDIT : my last example was missing the mainloop() function, so I recreated a better example from sentdex's youtube tutorial here [this video] Here is a shorter example of the code: import matplotlib matplotlib.use("TkAgg") from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import tkinter as tk LARGE_FONT = ("Verdana", 12) class SeaofBTCapp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack(side="top", fill="both", expand=True) containe
Cites Jeffrey · 2016-10 · Stack Overflow · on “Python data display with graph”
I am just dipping my toes into Python and have had help on here to get a live updating Matplotlib graph to work for me. This program uses animation to pull data from a dynamically growing CSV file with data that looks like the following: TimeStamp, ReadCount, Antenna, Protocol, RSSI, EPC, Sensor 09/28/2016 17:34:28.967, 5686, 2, GEN2, -25, E036115348A908CB, 23.16,0.00,0.00, (Infinity%), 09/28/2016 17:34:29.716, 5687, 2, GEN2, -32, E036115348A908CB, (Infinity%), 09/28/2016 17:34:31.155, 5689, 2, GEN2, -27, E036115348A908CB, 22.74,3.38, (Infinity%), 09/28/2016 17:34:32.351, 5692, 2, GEN2, -25, E036115348A908CB, 22.95,0.00,0.00,3.38, (Infinity%), 09/28/2016 17:34:32.895, 5695, 2, GEN2, -23, E03
Cites Sinead · 2017-06 · Stack Overflow · on “Replacing a figure on Tkinter Python”
I am using Tkinter and would like to have the option to clear my graph and draw a new one in its place. I'm not sure what to put in my callback to do this. The best I can do so far is to replace the graph with a white box. The new graph is drawn underneath (which isn't ideal) and also appears as a blank white box for some reason. Apologies for asking such a basic question but I'm new to python and couldn't find an example using subplots on here. import matplotlib matplotlib.use("TkAgg") from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import Tkinter as tk from Tkinter import * import ttk class Helmholtz_App(tk.Tk):
Cites siddsp · 2020-01 · Stack Overflow · on “Embedding a MatPlotLib Graph in Tkinter [.grid method], and Customizing MatPlotLib's Navigation Toolbar”
I've been having problems with embedding my MatPlotLib Graph in Tkinter, and after doing some searching on Google, and the MatPlotLib website, the best I could get was the standard method: import tkinter from matplotlib.backends.backend_tkagg import ( FigureCanvasTkAgg, NavigationToolbar2Tk) fig = Figure(figsize=(5, 4), dpi=100) canvas = FigureCanvasTkAgg(fig, master=root) canvas.draw() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) toolbar = NavigationToolbar2Tk(canvas, root) toolbar.update() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) Now if I try to replace the packing layout with a .grid (and remove the .pack() parameters), I get