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:
- Create a new Python module and save it as Matplotlib_labels.py.
- 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, ...