-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Snap selectors #21374
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
Snap selectors #21374
Conversation
This PR is affected by a re-writing of our history to remove a large number of accidentally committed files see discourse for details. To recover this PR it will need be rebased onto the new default branch (main). There are several ways to accomplish this, but we recommend (assuming that you call the matplotlib/matplotlib remote git remote update
git checkout main
git merge --ff-only upstream/main
git checkout YOUR_BRANCH
git rebase --onto=main upstream/old_master
# git rebase -i main # if you prefer
git push --force-with-lease # assuming you are tracking your branch If you do not feel comfortable doing this or need any help please reach out to any of the Matplotlib developers. We can either help you with the process or do it for you. Thank you for your contributions to Matplotlib and sorry for the inconvenience. |
cba7746
to
bda0a38
Compare
267d970
to
1fd11a4
Compare
What is the use case for this? I could imagine snapping to artist bounding boxes or points in a |
The motivation for libraries using matplotlib selectors is to support cases where only a subset of selection is valid. It is implemented in a generic manner to be flexible and avoid an heuristic approach. import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
import numpy as np
x = np.arange(8)
values = np.random.random(size=8)
snap_values = np.append(x-0.5, [x[-1] + 0.5])
_, ax = plt.subplots()
plt.plot(values, drawstyle='steps-mid')
span = SpanSelector(ax, print, direction='horizontal',
interactive=True,
drag_from_anywhere=True,
snap_values=snap_values) This is relevant for many detectors used in spectroscopy, digital camera, etc. |
Ok, for a SpanSelector this makes sense. I'm much more unclear what the API and desired effects should be for the 2D selectors. It seems that there x and y are just independent sets of snap-positions per axis. 1) You might want to have correlations, e.g. for IMHO one would have to carefully think through use cases and suitable API & behavior per Selector separately. Otherwise, we may end in a corner we don't want to be in. How about starting with SpanSelector, which seems pretty straight forward? And leave the other selectors for later? On a more conecptual note, it may (maybe at a later time) be desirable to inject the snap logic, i.e. pass a function in that does the snapping: |
For 2D selectors, it will be the same for images, which have been acquired with a digital camera, where the intensity of each pixels is expected to measure a number of events hitting this specific pixels. import matplotlib.pyplot as plt
from matplotlib.widgets import RectangleSelector
import numpy as np
values = np.random.random(size=(8, 8))
snap_values_2D = np.tile(np.mgrid[-0.5:8.5], (2, 1))
_, ax = plt.subplots()
plt.imshow(values)
rect = RectangleSelector(ax, print,
interactive=True,
drag_from_anywhere=True,
snap_values=snap_values_2D) For scatter, I don't know and indeed I don't think that it makes sense.
I explore a bit this option, but I couldn't get anyway nice. The approach of this PR has the big advantage of being simple. |
5bd6cd6
to
cd8c924
Compare
cd8c924
to
70792e9
Compare
Sorry for coming back on this only now, I rebased and added this feature for the |
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
PR Summary
Snap SpanSelector position to specific values.