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
[Bug]: Slider #25771
Comments
The slider is a bit of a red herring here, the actual problem is that This can be worked around by doing If I add code to ignore that we are being asked to use that line, then the red line disappears when you move the slider (which is correct, as the axes were cleared, and "animate" does not re-add that line (though it does update the ydata). Since it is an artist which is returned by your It is unclear to me whether we should be a bit more defensive to avoid erroring if an artist is removed from axes |
I lean towards saying "It is unexpected and indicative of an underlying error that an artist which has been removed to be returned from my animation function" and thus current behave should remain. But if we do decide to be a bit more defensive, the following diff accomplishes that: diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py
index 08f1075fb4..da648e333a 100644
--- a/lib/matplotlib/animation.py
+++ b/lib/matplotlib/animation.py
@@ -1156,6 +1156,7 @@ class Animation:
# Handles blitted drawing, which renders only the artists given instead
# of the entire figure.
updated_ax = {a.axes for a in artists}
+ updated_ax -= {None}
# Enumerate artists to cache Axes backgrounds. We do not draw
# artists yet to not cache foreground from plots with shared axes
for ax in updated_ax:
@@ -1169,7 +1170,8 @@ class Animation:
cur_view, ax.figure.canvas.copy_from_bbox(ax.bbox))
# Make a separate pass to draw foreground.
for a in artists:
- a.axes.draw_artist(a)
+ if a.axes is not None:
+ a.axes.draw_artist(a)
# After rendering all the needed artists, blit each Axes individually.
for ax in updated_ax:
ax.figure.canvas.blit(ax.bbox) |
Given the axes-centric ness of the animation code, I'm inclined to say that we should still error, but just a more understandable error. Probably at the places where Kyle's patch hits. |
More minimal reproducer, which strips out the Slider callback by just calling import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
N=1000
x = np.linspace(0, 1, N)
y = np.linspace(0, 1, N)
#plot
fig, ax = plt.subplots()
line, = ax.plot(x,y)
def init():
line.set_ydata(y)
return line,
def animate(i):
line.set_ydata(y * i)
return line,
def plot():
#camera
ax.clear()
#ax.add_line(line)
ani = animation.FuncAnimation(fig, animate, init_func=init, frames=100 ,interval=25, blit=True)
# Note calling plot here, instead of by a Slider
plot()
plt.show() Note that if you turn blitting off it does not crash, but nothing is drawn since the line is removed. (Well, and simply I'd propose to put the check a little earlier in the call stack, something like here, where we already do some raising of exceptions if unexpected values are returned: matplotlib/lib/matplotlib/animation.py Lines 1757 to 1770 in 2e2d2d5
Not sure it would resolve the segfault though, as that seems to be backend dependent and hard to ensure we don't do so:
Perhaps that is actually the underlying change, but regardless I think the red line from the original report would be missing, even if the animation continued without segfaulting/exception. |
Bug summary
I have found a bug with the slider object (matplotlib 3.7.1)
The script is joined.
It works very well with win 10 and ubuntu 22.04 and python3.11.2
It doesn't work with with win 10 and ubuntu 22.04 and python3.11.3
When I click on the slider, I have this message
ax is None
I suppose a bug from python 3.11.3 or matplotlib !!
Thanks a lot
Philippe DALET
Lyp Champollion
FIGEAC - FRANCE
Code for reproduction
Actual outcome
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 1226, in _on_timer
ret = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1426, in _step
still_going = super()._step(*args)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1119, in _step
self._draw_next_frame(framedata, self._blit)
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1139, in _draw_next_frame
self._post_draw(framedata, blit)
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1162, in _post_draw
self._blit_draw(self._drawn_artists)
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1177, in _blit_draw
cur_view = ax._get_view()
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_get_view'
Aborted (core dumped)
Expected outcome
crash
Additional information
No response
Operating system
windows 10 , Ubuntu 22.04
Matplotlib Version
3.7.1
Matplotlib Backend
QtAgg
Python version
3.11.3
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: