mpl-help
Backend-independent help windows for matplotlib figures.
Press a configurable trigger key (default h) inside any matplotlib figure to open a styled help panel listing your application's keyboard shortcuts and mouse controls.
- No external GUI toolkit — the help window is itself a matplotlib figure
- Config-file driven — define shortcuts in YAML, TOML, or JSON; no code changes needed per figure type
- Dark and light themes, with full per-colour overrides
- Per-section accent colours — named palette or arbitrary hex
- Adjustable key column width — accommodates both short keyboard shortcuts and longer mouse-event descriptions
- Closes with the figure it helps — or stays open, if you prefer
- Works with any matplotlib backend — TkAgg, Qt5Agg, Qt6Agg, WxAgg, …
Installation
Requires Python ≥ 3.11.
Local (editable) install
git clone https://github.com/bwohlberg/mpl-help
cd mpl-help
pip install -e ".[config]" # includes PyYAML for config file support
From PyPI (once published)
pip install mpl-help # matplotlib only, JSON config works out of the box
pip install "mpl-help[yaml]" # add YAML support
pip install "mpl-help[config]" # same, plus any future config extras
Quickstart
Programmatic API
import matplotlib.pyplot as plt
from mpl_help import HelpManager, HelpSection, KeyBinding
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
help_mgr = HelpManager(fig, title="My App — Help", theme="dark")
help_mgr.add_section(HelpSection(
title="Navigation",
accent="blue",
bindings=[
KeyBinding("?", "Show this help window"),
KeyBinding("q / Escape", "Close figure"),
KeyBinding("← → ↑ ↓", "Pan the active axes"),
],
note="Click a subplot first to make it active.",
))
help_mgr.attach()
plt.show()
Important: keep a reference to the
HelpManageralive (here:help_mgr) for the duration ofplt.show(). matplotlib's callback registry uses weak references, so if the manager is garbage-collected the keypress handler silently stops working. Ifattach()happens in a function that returns beforeplt.show()is called, return the manager from that function and hold onto it at the call site.
Config-file API
from mpl_help import load_manager
help_mgr = load_manager(fig, "my_app_help.yaml")
help_mgr.attach()
plt.show()
load_manager auto-detects the format from the file extension. The equivalent
in-process variants are also available:
from mpl_help import loads_manager, manager_from_dict
help_mgr = loads_manager(fig, yaml_text, fmt="yaml")
help_mgr = manager_from_dict(fig, config_dict)
Config file format
A minimal YAML config:
title: My App — Keyboard Shortcuts
sections:
- title: Navigation
accent: blue
bindings:
- key: h
desc: Show this help window
- key: "q / Escape"
desc: Close figure
note: Optional callout text shown below the bindings.
Top-level keys:
| Key | Type | Default | Description |
|---|---|---|---|
title |
str |
"Keyboard Shortcuts" |
Heading shown in the help window |
trigger_key |
str |
"?" |
Key that opens / closes the help window |
footer |
str |
auto | Small note at the bottom of the window |
key_column |
float |
0.24 |
Right edge of the key badge column, as a fraction of figure width |
close_with_figure |
bool |
true |
Close the help window when the monitored figure is closed |
sections |
list |
— | Ordered list of section blocks (required) |
Section keys:
| Key | Type | Default | Description |
|---|---|---|---|
title |
str |
— | Section heading (required) |
accent |
str |
"purple" |
Named palette colour or hex string |
bindings |
list |
— | List of {key, desc} pairs (required) |
note |
str |
none | Optional explanatory text below the bindings |
The config file deliberately has no theme or per-colour content — those are presentation concerns, set at load time (see Themes and palettes below), so the same config file works correctly under both themes.
See examples/example_help.yaml for a fully
annotated template, and examples/imview_help.yaml /
examples/volview_help.yaml for real-world
examples with a wider key column for mouse-event descriptions.
Supported formats
| Format | Extra dependency |
|---|---|
YAML (.yaml / .yml) |
pip install mpl-help[yaml] |
TOML (.toml) |
none — stdlib tomllib |
JSON (.json) |
none — always available |
The same content can also be supplied directly as a Python dict — see
examples/imview_help_dict.py for an example.
Themes and palettes
Two built-in themes are available: "dark" (default) and "light". Pass
theme= to HelpManager or to any of the loader functions:
HelpManager(fig, theme="light")
load_manager(fig, "my_app_help.yaml", theme="light")
Named accent colours (blue, green, orange, …) resolve to different hex
values depending on the active theme — deeper, more saturated tones on light
backgrounds and brighter tones on dark backgrounds — both chosen for
legibility. The config file only ever specifies the colour name; the
resolved value is purely a function of the active theme at render time.
| Name | Light hex | Dark hex |
|---|---|---|
blue |
#0969da |
#58a6ff |
purple |
#8250df |
#bc8cff |
green |
#1a7f37 |
#3fb950 |
yellow |
#9a6700 |
#d29922 |
orange |
#bc4c00 |
#ffa657 |
red |
#cf222e |
#f85149 |
cyan |
#1b7c83 |
#39c5cf |
Any CSS hex colour ("#f0a040") is also accepted as an accent and is used
as-is in both themes.
Overriding individual colours
Pass a palette dict to override any entry in DEFAULT_PALETTE, structural
or accent. Each value is a (light_hex, dark_hex) tuple:
from mpl_help import HelpManager, DEFAULT_PALETTE
print(DEFAULT_PALETTE.keys())
# dict_keys(['bg', 'surface', 'panel', 'border', 'text', 'muted',
# 'key_bg', 'key_fg', 'note_fg', 'note_bg', 'note_border',
# 'alt_row', 'top_bar', 'blue', 'purple', 'green',
# 'yellow', 'orange', 'red', 'cyan'])
help_mgr = HelpManager(
fig,
theme="light",
palette={
"blue": ("#1a5fb4", "#6ab0f5"), # (light_hex, dark_hex)
"bg": ("#fafafa", "#0a0d12"),
},
)
Unknown palette keys are silently ignored. palette is a presentation
argument like theme — it is never read from the config file.
Key column width
Short keyboard shortcuts (h, q / Escape) fit comfortably in the default
key column. Longer descriptions of mouse interactions — e.g.
"Mouse wheel (colorbar bottom half)" — need more room and will be clipped
or overflow the left margin at the default width. Widen the column with
key_column (a fraction of figure width, default 0.24):
load_manager(fig, "my_app_help.yaml", key_column=0.45)
key_column can also be set directly in the config file:
key_column: 0.45
A programmatic key_column= argument always overrides a value present in
the config file.
Closing the help window
By default the help window closes with the figure it belongs to: when the
monitored figure is closed — by its window close button, by matplotlib's
quit key, or by plt.close(fig) — any open help window for it closes too.
Pass close_with_figure=False to leave it open instead, in which case it is
closed by the user, by the trigger key, or by detach():
help_mgr = HelpManager(fig, close_with_figure=False)
The same option can be set in the config file:
close_with_figure: false
detach() always closes an open help window, whatever this option is set to.
Examples
The examples/ directory includes:
demo.py— exercises all three config-loading routes (file / string / dict) and both themes. Can be run from any directory:python examples/demo.py file --theme light python examples/demo.py string --theme dark python examples/demo.py dict --theme light
example_help.yaml/example_help.toml— fully annotated config templates covering every optionimview_help.yaml,imview_help.toml,imview_help_dict.py— real-world config for an image-viewing function, in all three supported formatsvolview_help.yaml,volview_help.toml,volview_help_dict.py— same, extended with volume-slice controls
API reference
HelpManager(fig, title, trigger_key, footer, theme, palette, key_column, close_with_figure)
| Parameter | Type | Default | Description |
|---|---|---|---|
fig |
Figure |
— | The matplotlib figure to monitor |
title |
str |
"Keyboard Shortcuts" |
Heading in the help window |
trigger_key |
str |
"?" |
Key that opens / closes the help window |
footer |
str | None |
auto | Note at the bottom of the window |
theme |
str |
"dark" |
"dark" or "light" |
palette |
dict | None |
None |
Per-instance palette overrides |
key_column |
float |
0.24 |
Right edge of key badge column (figure-width fraction) |
close_with_figure |
bool |
True |
Close the help window when the monitored figure is closed |
Methods:
.add_section(section)— append aHelpSection; chainable.attach()— start listening for the trigger key onfig.detach()— stop listening and close the help window if open.show()— open the help window programmatically
HelpSection(title, bindings, note, accent)
A titled group of key bindings. accent accepts a named palette colour, a
hex string, or None (defaults to "purple").
KeyBinding(key, description)
A single key/description pair.
load_manager(fig, path, theme="dark", palette=None, key_column=None, close_with_figure=None, encoding="utf-8")
Builds a HelpManager from a config file. Format auto-detected from extension.
loads_manager(fig, text, fmt, theme="dark", palette=None, key_column=None, close_with_figure=None)
Builds a HelpManager by parsing a config string. fmt is "yaml", "toml", or "json".
manager_from_dict(fig, config, theme="dark", palette=None, key_column=None, close_with_figure=None)
Builds a HelpManager directly from a Python dict.
DEFAULT_PALETTE
Dict of {name: (light_hex, dark_hex)} — the built-in colour set. Pass a
subset to palette= to override individual entries.
ACCENT_NAMES
The set of valid named accent colours: blue, purple, green, yellow,
orange, red, cyan.
Development
pip install -e ".[dev]"
pytest
Changelog
See CHANGELOG.md.
License
BSD 3-Clause — see LICENSE.txt.
Acknowledgements
Development of this package involved extensive use if Claude Code.
Metadata
Release files for mpl-help 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mpl_help-0.1.0.tar.gz | 26.9 kB | Without provenance | Details for mpl_help-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mpl_help-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mpl_help-0.1.0-py3-none-any.whl |
Total release size: 45.8 kB
Release files / mpl_help-0.1.0.tar.gz
| Download URL | mpl_help-0.1.0.tar.gz |
|---|---|
| Size | 26.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
205174682f0ab8607006eaedea3b40e2cba7896339fae0efcf6935da1822b19c
|
|
BLAKE2b-256 checksum How to use checksums |
bb52afcf2ad22a446e8bb5314400c5545219080e1349ce1bda474bb9bf4e9803
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / mpl_help-0.1.0-py3-none-any.whl
| Download URL | mpl_help-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86fea0e1b54059a6e6d1cebcf0e40013660d95b02546b421be93994d6efee748
|
|
BLAKE2b-256 checksum How to use checksums |
e60e76ccdd0eb7d7ca48a246747a37f3f897c01322a5f245f8509ef9306c8686
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Security for mpl-help 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.