Skip to content
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

Fix centre square rectangle selector part 1 #21604

Merged

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented Nov 11, 2021

@dstansby, as mentioned in #20839 (comment), this is the first part of #20839.

PR Summary

  • Fix centre and square state of rectangle selector in interactive mode. These states were working only when creating the selector.
  • Fix name coordinate handle: N and S were swapped.
  • Rebased on latest main branch.
import matplotlib.pyplot as plt
from matplotlib.widgets import RectangleSelector
import numpy as np

values = np.arange(0, 100)

fig = plt.figure()
ax = fig.add_subplot()
ax.plot(values, values)

selector = RectangleSelector(ax, print, interactive=True, drag_from_anywhere=True)

# change the size of selector interactively

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.

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Looks good overall - I've left a few suggestions and questions.

lib/matplotlib/widgets.py Outdated Show resolved Hide resolved
lib/matplotlib/widgets.py Show resolved Hide resolved
lib/matplotlib/widgets.py Show resolved Hide resolved
lib/matplotlib/widgets.py Show resolved Hide resolved
lib/matplotlib/widgets.py Outdated Show resolved Hide resolved
lib/matplotlib/widgets.py Outdated Show resolved Hide resolved
lib/matplotlib/tests/test_widgets.py Show resolved Hide resolved
Copy link
Member Author

@ericpre ericpre left a comment

Choose a reason for hiding this comment

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

Thanks, all comments should have been addressed!

lib/matplotlib/tests/test_widgets.py Show resolved Hide resolved
lib/matplotlib/widgets.py Show resolved Hide resolved
lib/matplotlib/widgets.py Outdated Show resolved Hide resolved
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Thanks - all looks good to me!

@dstansby
Copy link
Member

I think this is a bugfix, so going to milestone to 3.5.x - second reviewer feel free to correct me on this.

@dstansby dstansby added this to the v3.5.1 milestone Nov 12, 2021
@ericpre
Copy link
Member Author

ericpre commented Nov 13, 2021

Thanks @dstansby, once the second review is done and this PR is merged, I will see how to split the rest of #20839.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

@ericpre Since you plan a followup PR, the comment on using tuples can be addressed therein. I'll merge as is to enable you continuing with that PR.

Comment on lines +2973 to +2974
size_on_press = [x1 - x0, y1 - y0]
center = [x0 + size_on_press[0] / 2, y0 + size_on_press[1] / 2]
Copy link
Member

Choose a reason for hiding this comment

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

I would use tuples instead of lists for coordinates.

@timhoffm timhoffm merged commit 993c1bc into matplotlib:main Nov 14, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Nov 14, 2021
dstansby added a commit that referenced this pull request Nov 15, 2021
…604-on-v3.5.x

Backport PR #21604 on branch v3.5.x (Fix centre square rectangle selector part 1)
@QuLogic QuLogic modified the milestones: v3.5.1, v3.5.0 Nov 15, 2021
@ericpre ericpre modified the milestones: v3.5.0, v3.6.0 Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants