Data Visualization in Python with Matplotlib and Pandas - Matplotlib Widgets

Matplotlib Widgets

David Landup
David Landup

Matplotlib isn't only for static plots. While GUIs are typically created with GUI libraries and frameworks such as PyQt, Tkinter, Kivy and wxPython, and while Python does have excellent integration with PyQt, Tkinter and wxPython - there's no need to use any of these for some basic GUI functionality, through Matplotlib Widgets.

The matplotlib.widgets module has several classes, including the AxesWidget, out of which Buttons, CheckButtons, Sliders, TextBoxes, etc are derived. These all accept the Axes they're being added to as the one and only mandatory constructor argument, and their positioning has to be manually set. A thing to note is that the widget is the axes, so you'll create an Axes instance for each widget.

Another thing to note is that you have to keep references to the widgets otherwise, they might get garbage collected.

Each of them can also be disabled by setting active to False, in which case, they won't respond to any events, such as being clicked on. That being said, we can introduce a new type of interactivity to our plots, through various GUI elements and components.

Note: Matplotlib isn't meant to be used for high-quality GUI creation, nor user-friendly systems. These widgets are rudimentary, don't really look great and have limited functionality. They're meant as a way to prototype and test things out, rather than actually ship them.

Start course to continue
Lessson 9/10
You must first start the course before tracking progress.
Mark completed

© 2013-2022 Stack Abuse. All rights reserved.

DisclosurePrivacyTerms