-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix drawing animated artists changed in selector callback #21342
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 drawing animated artists changed in selector callback #21342
Conversation
I like the general approach more here. |
Yes, I agree, this is much better! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+/- stylistic point above.
b6475bc
to
515aa53
Compare
In 515aa53, I remove the Adapting one of the blitting example: import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
import numpy as np
x = np.linspace(0, 2 * np.pi, 100)
values = np.sin(x)
fig, ax = plt.subplots()
(ln,) = ax.plot(x, values, animated=True)
(ln2 , ) = ax.plot([], animated=True)
plt.show(block=False)
plt.pause(0.1)
bg = fig.canvas.copy_from_bbox(fig.bbox)
ax.draw_artist(ln)
fig.canvas.blit(fig.bbox)
def mean(vmin, vmax):
indmin, indmax = np.searchsorted(x, (vmin, vmax))
v = values[indmin:indmax].mean()
ln2.set_data(x, v)
span = SpanSelector(ax, mean, direction='horizontal',
onmove_callback=mean,
interactive=True,
drag_from_anywhere=True,
useblit=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks 👍 - is there a test we an add for this?
453b4cd
to
1e988b3
Compare
I have added a test and switch to list comprehension instead of using filter. |
2a5c86c fixes an issue with zorder of the artists. Before 2a5c86c, the selector artists will be drawn before other artists and therefore it was behind, as in the following example: import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
import numpy as np
values = np.ones((10, 10))
fig, ax = plt.subplots()
ax.imshow(values, animated=True)
span = SpanSelector(ax, print, direction='horizontal',
interactive=True,
drag_from_anywhere=True,
useblit=True) when sorting the artists order, all artists need to sorted together! |
@dstansby, any chance you can have a look at this again, please? Thanks! |
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. |
991cdb6
to
67f6c90
Compare
67f6c90
to
a189593
Compare
Can anyone review this PR, please? |
@dstansby, if this PR looks good to you - from your comment in #21342 (review); can you please approve and merge? :) Thanks! |
lib/matplotlib/widgets.py
Outdated
Convenience method to get all animated artists of a figure, except | ||
those already present in self.artists. 'z_order' is ignored. | ||
""" | ||
return tuple([a for ax_ in self.ax.get_figure().get_axes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a tuple and not a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason.
a189593
to
ea8e6c9
Compare
lib/matplotlib/widgets.py
Outdated
return tuple([a for ax_ in self.ax.get_figure().get_axes() | ||
for a in ax_.get_children() | ||
if a.get_animated() and a not in self.artists]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return tuple([a for ax_ in self.ax.get_figure().get_axes() | |
for a in ax_.get_children() | |
if a.get_animated() and a not in self.artists]) | |
return tuple(a for ax_ in self.ax.get_figure().get_axes() | |
for a in ax_.get_children() | |
if a.get_animated() and a not in self.artists) |
if we are going with a tuple might as well not bother with the list in the middle. I have a slight preference for tuple over list because immutablability is good, but given that his is an internal API either is fine with me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
ea8e6c9
to
2eb2b32
Compare
2eb2b32
to
7603999
Compare
Rebased to get the test suite to pass, can anyone merge this PR? |
PR Summary
Alternative to #20977.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).