{"id":4123,"library":"mplcursors","title":"Interactive data selection cursors for Matplotlib","description":"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.","status":"active","version":"0.7.1","language":"en","source_language":"en","source_url":"https://github.com/anntzer/mplcursors","tags":["matplotlib","plotting","interactive","cursors","data visualization","annotations"],"install":[{"cmd":"pip install mplcursors","lang":"bash","label":"Install from PyPI"},{"cmd":"conda install conda-forge::mplcursors","lang":"bash","label":"Install with Conda"}],"dependencies":[{"reason":"Core dependency for plotting, requires Matplotlib>=3.1.","package":"matplotlib","optional":false},{"reason":"Requires Python version >=3.7.","package":"python","optional":false},{"reason":"Often used with Matplotlib for data generation.","package":"numpy","optional":true}],"imports":[{"note":"The primary function to enable interactive cursors on a plot or specific artists.","symbol":"cursor","correct":"from mplcursors import cursor"}],"quickstart":{"code":"import matplotlib.pyplot as plt\nimport numpy as np\nimport mplcursors\n\n# Generate some data\ndata = np.outer(range(10), range(1, 5))\nfig, ax = plt.subplots()\nlines = ax.plot(data)\n\nax.set_title(\n    \"Click somewhere on a line.\\nRight-click to deselect.\\n\" \"Annotations can be dragged.\"\n)\n\n# Enable interactive cursors on the plotted lines\nmplcursors.cursor(lines, hover=False) # hover=False means click to activate\n\nplt.show()","lang":"python","description":"This basic example demonstrates how to create a simple Matplotlib plot and then apply `mplcursors.cursor()` to enable interactive data selection and draggable annotations on the plotted lines. A left click creates a draggable annotation, and a right click removes it."},"warnings":[{"fix":"Update code accessing `Selection.target.index` to `Selection.index`. `Selection.target.index` was deprecated in 0.5 and will be removed.","message":"The `index` attribute of a `Selection` object changed its path. It is now a direct attribute of `Selection`, not `Selection.target.index`.","severity":"breaking","affected_versions":"0.5 and later"},{"fix":"Add `\"mplcursors:install\"` to `mpl.rcParams[\"figure.hooks\"]` for global `MPLCURSORS` environment variable activation (requires Matplotlib>=3.7).","message":"When using the `MPLCURSORS` environment variable for global configuration, explicit registration in `mpl.rcParams['figure.hooks']` is now required.","severity":"breaking","affected_versions":"0.7 and later"},{"fix":"Avoid using `mplcursors` with Matplotlib's blitting-enabled animations, or consider alternative approaches for interactivity in such scenarios.","message":"Annotations may not display correctly or disappear when using Matplotlib's animation blitting mode due to conflicts in artist drawing control.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all desired artists are present when `mplcursors.cursor()` is called, or explicitly pass a list of artists/axes to `mplcursors.cursor()` including dynamically added ones.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the `mplcursors` changelog or documentation for specific Matplotlib compatibility requirements. Upgrade or downgrade Matplotlib if encountering issues.","message":"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).","severity":"gotcha","affected_versions":"Various, depending on `mplcursors` and `matplotlib` versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}