You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To better support interactivity and contextual data, we should support data tooltips.
Proposed solution
Things to be done:
Add tooltip API to backend_bases. This should be similar to the picker functionality, only with hover instead of click. T.b.d.: Do we want a TooltipEvent or a more general HoverEvent?
Implement that API for the backends. As a first step or prove of concept one could start with one backend, e.g. Qt and add the other backends later. ipympl could/should follow at some point as well.
Add high-level API to support setting tooltips.
We likely want at least:
explicit strings: plt.plot(x, y, tooltip=['A', 'B', 'C', 'D'])
data support: plt.plot('x', 'y', tooltip='label', data=data)
functions: plt.plot(x, y, tooltip=lambda x, y: f'({x}, {y})')
Reacted by hannah, Ian Hunt-Isaak, Eli Slothower and lhg1992
Is this different than the existing cursor coord readout? I far prefer a readout in the corner to a data tooltip because it doesn't cover my data more than the mouse already does....
Some group members and I are working on implementing tooltip support for this issue, and we're looking for guidance on the most efficient way to handle the high-level API.
Rather than modifying each plotting function individually (e.g., plot(), scatter(), bar(), etc.) to accept a hover parameter, is there a preferred approach for applying this functionality across all plotting functions?
We’re wondering if there’s:
A shared wrapper, internal dispatcher, or base function we could hook into,
A decorator pattern that could be reused,
Or perhaps an existing mechanism (like how data or label are handled) that we could align with?
Our goal is to avoid duplicating logic while ensuring consistent behavior and maintaining backward compatibility. Any suggestions on where best to integrate this or references to similar patterns used in the codebase would be appreciated.
You can and probably should add this to the Artist base class - get/set_tooltip. This will be propagated though **kwargs by most plotting functions, just like label. Though you'll likely need per-Artist-subclass specific implementation of data mapping, i.e. what is the tooltip for a given data coordinate.
That said, you don't have to implement all Artists right away. I suggest starting with Line2D. If you manage to to do 1., 2. and a specific version of 3. for Line2D, you've come quite far. We can generalize the high level API subsequently.
@Dil003 to follow on Tim's comment, you may also want to look at the data cursor mechanism/API folks have been discussing b/c it's got somewhat similar functionality and possibly look at how some of the third party packages implement it.
Activity
jklymak commentedon Jul 1, 2022
Is this different than the existing cursor coord readout? I far prefer a readout in the corner to a data tooltip because it doesn't cover my data more than the mouse already does....
timhoffm commentedon Jul 2, 2022
This is different because you can show arbitrary data, not just the coordinates.
tacaswell commentedon Jul 3, 2022
My instinct is a
HoverEvent(and anUnHoverEvent?) and add a genericshow_tooltip/hide_tooltipmethods on theCanvasclassesHow does this interact with the existing
mouseover/get_cursor_datafunctionality?timhoffm commentedon Jul 4, 2022
T.b.d. I think
get_cursor_datais quite limited in its output because it has to fit in a single line in the gui.I'm looking for things like this:
https://docs.bokeh.org/en/latest/docs/user_guide/tools.html#hovertool
https://plotly.com/python/hover-text-and-formatting/
in particular also the ability to show context information on data points, which
get_cursor_datacurrently does not have.story645 commentedon Jul 4, 2022
How does this differ from how https://mplcursors.readthedocs.io/ and https://github.com/joferkington/mpldatacursor implement hovering/would it make those libraries way simpler?
oscargus commentedon Jul 15, 2022
This should, btw, also be possible to support in the PDF and SVG backends.
tacaswell commentedon Jul 16, 2022
I think we even have a demo of post-processing an SVG to add tooltips.
timhoffm commentedon Jul 17, 2022
https://matplotlib.org/devdocs/gallery/user_interfaces/svg_tooltip_sgskip.html
oscargus commentedon May 28, 2023
Slightly related: #9957
Dil003 commentedon May 14, 2025
Hi there,
Some group members and I are working on implementing tooltip support for this issue, and we're looking for guidance on the most efficient way to handle the high-level API.
Rather than modifying each plotting function individually (e.g., plot(), scatter(), bar(), etc.) to accept a hover parameter, is there a preferred approach for applying this functionality across all plotting functions?
We’re wondering if there’s:
A shared wrapper, internal dispatcher, or base function we could hook into,
A decorator pattern that could be reused,
Or perhaps an existing mechanism (like how data or label are handled) that we could align with?
Our goal is to avoid duplicating logic while ensuring consistent behavior and maintaining backward compatibility. Any suggestions on where best to integrate this or references to similar patterns used in the codebase would be appreciated.
Thanks in advance!
timhoffm commentedon May 15, 2025
You can and probably should add this to the Artist base class -
get/set_tooltip. This will be propagated though **kwargs by most plotting functions, just likelabel. Though you'll likely need per-Artist-subclass specific implementation of data mapping, i.e. what is the tooltip for a given data coordinate.That said, you don't have to implement all Artists right away. I suggest starting with Line2D. If you manage to to do 1., 2. and a specific version of 3. for Line2D, you've come quite far. We can generalize the high level API subsequently.
story645 commentedon May 15, 2025
@Dil003 to follow on Tim's comment, you may also want to look at the data cursor mechanism/API folks have been discussing b/c it's got somewhat similar functionality and possibly look at how some of the third party packages implement it.
Draft PR: On adding data tooltip support (matplotlib#23378)