How to do it...

While plot is the easiest way to create a Matplotlib chart, using Figure in combination with Canvas creates a more custom-made graph, which looks much better and also enables us to add buttons and other widgets to it:

  1. Create a new Python module and save it as Matplotlib_labels.py.
  2. Type the following code into the module:
from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import tkinter as tk #-------------------------------------------------------------- fig = Figure(figsize=(12, 8), facecolor='white') #-------------------------------------------------------------- # axis = fig.add_subplot(111) # 1 row, 1 column, only graph   #<-- uncommentaxis = fig.add_subplot(211) # 2 rows, ...

Get Python GUI Programming Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.