Here are resources and additional documentation about Matplotlib and PySimpleGUI:
00:13 Matplotlib can create all kinds of different graphs. If you’d like to know more about it, check out Python Plotting With Matplotlib. Matplotlib can be integrated with PySimpleGUI, so you can add graphs to your GUI fairly easily if you already know how to use Matplotlib.
Now that you have all the pieces you need to write the code, you can create a new file called
psg_matplotlib.py. The demo code is a little long, so let’s look at it in pieces starting with this first section.
These are the imports you’ll need to make your code work. This code also sets up the Matplotlib
Figure() and adds a plot using
.add_subplot(). For more details, you may want to refer to the documentation.
You can read more about that in the documentation. Now you can create a helper function to draw the figure on PySimpleGUI’s
Canvas(). A helper function is repetitive code that you don’t want to write multiple times.
To use PySimpleGUI’s
Canvas(), you need to pass it into
FigureCanvasTkAgg() along with the Matplotlib
FigureCanvasTkAgg() comes from Matplotlib and is used by Tkinter to embed the plots in PySimpleGUI.
This would work differently if you were using PySimpleGUIQt. The last step is to write the user interface with PySimpleGUI. This is simpler than the previous image viewer interface, as the
layout only consists of three elements.
03:27 There are other Matplotlib demos included with PySimpleGUI that you should check out. Now that you’ve seen how to integrate Matplotlib with PySimpleGUI, in the next section you’ll see how to integrate computer vision with the OpenCV library.
Become a Member to join the conversation.