Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Data tooltip support #25831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open

Data tooltip support #25831

wants to merge 51 commits into from

Conversation

yanxinc
Copy link

@yanxinc yanxinc commented May 8, 2023

PR summary

Closes #23378

This adds data tooltip support to the tkinter, qt, gtk3, gtk4, and wx backend. The tooltip is added as a label in the bottom right hand corner whenever the cursor hovers over a data point.

import matplotlib
import matplotlib.pyplot as plt
from numpy.random import rand
matplotlib.use('tkagg')

fig, ax = plt.subplots()
ax.plot(rand(100), 'o', hover=True)
plt.show()

The tooltip can also be set with a list of explicit strings or a user-defined function.

  • explicit string: ax.plot(rand(3), 'o', hover=['London', 'Paris', 'Barcelona'])

  • user-defined function:

def user_defined_function(event):
    x, y = round(event.xdata * 10, 1), round(event.ydata + 3, 3)
    return f'({x}, {y})'

ax.plot(rand(100), 'o', hover=user_defined_function)
  • data dictionary:
x = rand(3)
y = rand(3)
ax.plot(x, y, 'o', hover={(x[0], y[0]): "London", (x[1], y[1]): "Paris", (x[2], y[2]): "Barcelona"})

PR checklist

eslothower and others added 30 commits April 17, 2023 17:38
Add tooltip API to backend_bases.py and get/set_hover() to artist.pyi
task 2 - added hover backend implementation & tk specific label
Remove figure not None check
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@eslothower
Copy link

Looks good! Ready to review.

@yanxinc yanxinc marked this pull request as ready for review May 8, 2023 03:11
Copy link
Member

@ksunden ksunden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looked closely at the things that were flagging CI such as sphinx warnings.

Broad strokes, I think it looks pretty good, though I would want to take a bit more time to play around with it.

I do think that if this requires changes to other backends we should at least have a plan for achieving feature parity where possible (particularly for gui backends, as this seems to edit tk and qt, but not some of the other options). That doesn't necessarily have to be done in this PR, but having a plan would be good.

Do you feel comfortable squashing commits down? if not, we can do so on merge.

lucychencys and others added 2 commits May 19, 2023 16:34
#9)

* implemented hover feature for other backends; fixed string list; added dict

* fix linter issues

* more linter issues

---------

Co-authored-by: Yanshi Chen <[email protected]>
* implemented hover feature for other backends; fixed string list; added dict

* fix linter issues

* more linter issues

* fix documentations

---------

Co-authored-by: Yanshi Chen <[email protected]>
@yanxinc yanxinc requested a review from ksunden May 20, 2023 00:04
@anntzer
Copy link
Contributor

anntzer commented May 21, 2023

Based on #23378 (comment) I assume @timhoffm's intent was to have some real "native" tooltip which does not live in the toolbar, but can instead span multiple lines.

@tacaswell
Copy link
Member

Thank you for this work, however we are currently unlikely to take it in it's current state.

We have two major concerns:

  • There is not yet a consensus that we want to add a HoverEvent to our set of events
  • The primary thing that [ENH]: Data tooltip support #23378 was asking for was "native" tooltip support (like we have a "native" rectangle for the zoombox). Getting that in first is a prerequisite for considering if we want a HoverEvent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[ENH]: Data tooltip support
10 participants