How to Add Legends in TKinter Matplotlib Window

In this Python TKinter article i want to show How To Add Legends In TKinter Matplotlib Window. so first of all let’s talk about TKinter and Matplotlib.

 

 

 

What is TKinter?

Tkinter is standard Python library, and it is used to build graphical user interfaces (GUIs). The name of Tkinter comes from Tk interface,  and it provides Python bindings for Tk GUI toolkit. Tkinter is included with most Python installations, and you don’t need to install TKinter. using TKinter you can create desktop applications for different platforms, including Windows, macOS and Linux.

 

 

 

What Is Matplotlib ? 

Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shells, the Jupyter notebook, web application servers, and four graphical user interface toolkits.

 

 

 

How to Install Matplotlib?

You can install matplotib using pip, open your command prompt or terminal and write this command.

 

 

How to Add Legends in TKinter Matplotlib Window

So now this is the complete code for this article

 

 

 

 

 

First of all we have imported our required classes that we need, basically we need the class from tkinter library along with matplotlib library.

 

 

 

So this is the method that we are going to create our Matplotlib canvas, with our data that we want to plot also in this method we create the legends.

 

 

 

These are the values that we want to plot

 

 

 

These are the labels for our Matplotlib.

 

 

 

This is the legends for our Matplotlib.

 

 

 

 

Run the complete code and this will be the result

How to Add Legends in TKinter Matplotlib Window
How to Add Legends in TKinter Matplotlib Window

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×