8000 Add an example showing alternate mouse cursors. by QuLogic · Pull Request #20744 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add an example showing alternate mouse cursors. #20744

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

Merged
merged 1 commit into from
Jul 29, 2021

Conversation

QuLogic
Copy link
Member
@QuLogic QuLogic commented Jul 27, 2021

PR Summary

This makes it easy to test that cursors are working in a new backend (or if we add new cursors).

I'm not sure if it belongs in the widgets section.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [n/a] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [n/a] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [n/a] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@QuLogic QuLogic added this to the v3.5.0 milestone Jul 27, 2021
@timhoffm
Copy link
Member

If we are ok with a row-only layout, we can simplify the code considerably:

import matplotlib.pyplot as plt
from matplotlib.backend_tools import Cursors


fig, axs = plt.subplots(len(Cursors), gridspec_kw={'hspace': 0})
fig.suptitle('Hover over an Axes to see alternate Cursors')

for ax, cursor in zip(axs.flat, Cursors):
    ax.cursor_to_use = cursor
    ax.text(0.5, 0.5, cursor.name,
            horizontalalignment='center', verticalalignment='center')
    ax.set(xticks=[], yticks=[])


def hover(event):
    if fig.canvas.widgetlock.locked():
        # Don't do anything if the zoom/pan tools have been enabled.
        return

    fig.canvas.set_cursor(
        event.inaxes.cursor_to_use if event.inaxes else Cursors.POINTER)


fig.canvas.mpl_connect('motion_notify_event', hover)

plt.show()

grafik

@QuLogic
Copy link
Member Author
QuLogic commented Jul 28, 2021

It's just a ploy for that alternative layout generator that people wanted 😛 But more seriously, I think the square aspect is a better mouse target than the wide and short ones. And if we add more cursors, it might get even more cramped.

@timhoffm
Copy link
Member

The question is what the goal of the example is.

Is this about the code that is needed to change mouse cursors? Or is this only about showing the cursors? If the former, less distracting code is better. If the latter, I'm tempted to say that an example is too much effort for this. Users need to copy the code and run it. Showing some screenshots might be a simpler solution.

@QuLogic
Copy link
Member Author
QuLogic commented Jul 29, 2021

I'd rather not screenshots; cursors are backend dependent, and I'm not going to take (# backends)*(# cursors) screenshots. And everything in widgets needs to be run to see what they do, so I don't think that's much of an argument against the example. But if simplifying gets it in, I'll do that.

@timhoffm timhoffm merged commit 0cf55c1 into matplotlib:master Jul 29, 2021
@QuLogic QuLogic deleted the cursor-example branch July 29, 2021 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0