Interactive data selection cursors for Matplotlib
mplcursors provides interactive data selection cursors for Matplotlib. It is inspired by mpldatacursor, offering a simplified API to add dynamic tooltips and annotations to plots, enhancing data exploration. The library is actively maintained, with its current version 0.7.1 released in March 2026.
Warnings
- breaking The `index` attribute of a `Selection` object changed its path. It is now a direct attribute of `Selection`, not `Selection.target.index`.
- breaking When using the `MPLCURSORS` environment variable for global configuration, explicit registration in `mpl.rcParams['figure.hooks']` is now required.
- gotcha Annotations may not display correctly or disappear when using Matplotlib's animation blitting mode due to conflicts in artist drawing control.
- gotcha Artists added to the figure *after* the initial figure draw (e.g., in interactive sessions or callbacks not using `pyplot` directly) may not be picked up by `mplcursors` by default.
- gotcha There have been known incompatibilities with specific Matplotlib versions (e.g., Matplotlib 3.10.3 was marked incompatible in `mplcursors` 0.7, and 3.7.1 in 0.5.3).
Install
-
pip install mplcursors -
conda install conda-forge::mplcursors
Imports
- cursor
from mplcursors import cursor
Quickstart
import matplotlib.pyplot as plt
import numpy as np
import mplcursors
# Generate some data
data = np.outer(range(10), range(1, 5))
fig, ax = plt.subplots()
lines = ax.plot(data)
ax.set_title(
"Click somewhere on a line.\nRight-click to deselect.\n" "Annotations can be dragged."
)
# Enable interactive cursors on the plotted lines
mplcursors.cursor(lines, hover=False) # hover=False means click to activate
plt.show()