-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix drawing animated artist updated in selector callback #20977
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 artist updated in selector callback #20977
Conversation
Switch documented deprecations in mathtext by `__getattr__` deprecations
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
…_output API: rename draw_no_output to draw_without_rendering
Make warning for no-handles legend more explicit.
Remove unused HostAxes._get_legend_handles.
Redirect to new 3rd party packages page
legend_handler_map cleanups.
Clean up some Event class docs.
- parse() already normalizes prop=None to prop=FontProperties(). - We don't need to explicitly attach a canvas to a plain Figure() before calling savefig() anymore; FigureCanvasBase is always attached and handles the dispatching to the correct concrete canvas class.
According to the docs, this function was added in GTK 2.2, so probably was only needed when we supported GTK2. It also no longer exists in GTK4.
Since these examples don't need to support the very oldest GTK3, I took the opportunity to rewrite them using the recommended Application-styled model.
The `Gtk.Window.destroy` doesn't work, but `.close` correctly triggers our cleanup.
ENH: Adding callbacks to Norms for update signals
BUG: Fix f_back is None handling
Small cleanups to math_to_image.
Add a GTK4 backend.
Build wheels for Apple Silicon.
Mostly D401 (imperative mood) fixes, and a few other things.
Docstring cleanups.
…he artists to the `depending_artists` list attribute, we can update them in the `updating_background` and `update` methods.
… changed in callback
I'm sorry I can't follow. Can you please give a bit more context:
|
Thanks @timhoffm, it seems that you are following as well as I do, and yes, it does need more context! :)
The issue was already there:
With #20693 the previous workaround doesn't work anymore because the
Agreed, I will explain more once we figure out what should be done.
I also find this approach odd and this issue has been puzzling me for a while without finding a clearly convincing solution. The other alternative I could think of is to figure out what are the animated of the figure and draw them all explicitly in the selector
Yes, makes sense. |
Would it be possible to get this PR in for 3.5? To reproduce the issue (from the example adapted in this PR): import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
# Fixing random state for reproducibility
np.random.seed(19680801)
fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))
x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2 * np.pi * x) + 0.5 * np.random.randn(len(x))
ax1.plot(x, y)
ax1.set_ylim(-2, 2)
ax1.set_title('Press left mouse button and drag '
'to select a region in the top graph')
line2, = ax2.plot([], [])
# if the line is animated, it will not be drawn
line2, = ax2.plot([], [], animated=True)
def onselect(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax))
indmax = min(len(x) - 1, indmax)
region_x = x[indmin:indmax]
region_y = y[indmin:indmax]
if len(region_x) >= 2:
line2.set_data(region_x, region_y)
ax2.set_xlim(region_x[0], region_x[-1])
ax2.set_ylim(region_y.min(), region_y.max())
fig.canvas.draw_idle()
span = SpanSelector(
ax1,
onselect,
"horizontal",
# useblit=True, # it doesn't matter if blitting is used or not
props=dict(alpha=0.5, facecolor="tab:blue"),
interactive=True,
drag_from_anywhere=True
)
plt.show() |
Anyone to review this PR? Once we are happy with the fix, I will finish the user-facing documentation. |
I think I see the point of this PR, but I don't really like the solution: it is too manual and requires fiddling with rather internal parts of the library. I wonder if an alternative solution (approximately) like the following would be possible: when, in |
Yes, I have thought about something along these lines but I was concerned that it would redraw animated artists which wouldn't need to be redrawn and therefore defy the purpose of using animated artists and blitting. I consider it again but with using the |
Moved to draft since this seems superseded. |
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. |
Closing in favour of #21342. |
PR Summary
Fix drawing animated artists (external to selector artists itself), which are updated in selector callback - see changes in doc example: the animated line will not drawn if the selector doesn't draw it when updating itself.
I am not sure if it deserves a new feature entry.
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).