TKinter Tutorial
About Lesson

In this tutorial we are going to learn about TKinter Embed Matplotlib, we want to learn how you can embed matplotlib graphs in tkinter.



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.


First of all you need to install matplotlib.




This is the complete code for this article.




First we need to create a figure, also we are going to give the figure size.



we have used subplot grid parameters encoded as a single integer. For example, “111” means “1×1 grid, first subplot” and “234” means “2×3 grid, 4th subplot”.



This is the data that we want to plot in the tkinter window, basically it is just a simple line with the x and y positions.




Also you need to create the object for the canvas, because the graph should be a canvas.




Using this we can show our canvas.




In these line of codes we are going to use pack layout manager.




Run the complete code and this is the result.

TKinter Embed Matplotlib
TKinter Embed Matplotlib