When Matplotlib is used from Python shell, the plots are displayed in a default window. The plots can be embedded in many graphical user interfaces like wxpython, pygtk, or Tkinter. These various options available as a target for the output plot are referred to as ‘backends‘. There are various modules available in matplotlib.backend for choosing the backend. One such module is backend_tkagg which is useful for embedding plots in Tkinter.
Creating the Tkinter Application :
First, let us create a basic Tkinter application with the main window and one button which can be used to display the plot.
Embedding the Plot:
First, we need to create the figure object using the Figure() class. Then, a Tkinter canvas(containing the figure) is created using FigureCanvasTkAgg() class. Matplotlib charts by default have a toolbar at the bottom. When working with Tkinter, however, this toolbar needs to be embedded in the canvas separately using the NavigationToolbar2Tk() class.
In the implementation below, a simple graph for:
is plotted. The plot function is bound to a button that displays the figure when pressed.
- Python GUI - tkinter
- Python | Simple GUI calculator using Tkinter
- Python | Distance-time GUI calculator using Tkinter
- Python - Compound Interest GUI Calculator using Tkinter
- Python | Create a GUI Marksheet using Tkinter
- Python: Weight Conversion GUI using Tkinter
- Python | ToDo GUI Application using Tkinter
- Python | GUI Calendar using Tkinter
- Sentiment Detector GUI using Tkinter - Python
- Python - Morse Code Translator GUI using Tkinter
- Create First GUI Application using Python-Tkinter
- Rank Based Percentile Gui Calculator using Tkinter
- Python - SpongeBob Mocking Text Generator GUI using Tkinter
- Python - Spell Corrector GUI using Tkinter
- Python - UwU text convertor GUI using Tkinter
- GST Rate Finder GUI using Python-Tkinter
- Create Copy-Move GUI using Tkinter in Python
- Python - English (Latin) to Hindi (Devanagiri) text convertor GUI using Tkinter
- Standard GUI Unit Converter using Tkinter in Python
- GUI chat application using Tkinter in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.