-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Why does setting imshow(animated=True) still show an image? #18985
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
Comments
I just saw this as well after reading that tutorial. This feels like a bug to me. I think the relevant lines are: matplotlib/lib/matplotlib/axes/_base.py Lines 2818 to 2821 in c1e0211
which was introduced in #4014 with the commit message "Guard against removing animated images" Although I can't see any discussion of this in the discussion on the PR. So it looks like images are being treated specially, but I totally don't understand why. Anyone with deeper knowledge of matplotlib artists know what's going on? |
Commenting out the check for There some mention in the PR of "The great artist rewrite of '15", Maybe after that rewrite this guard was no longer necessary? |
It was almost 6 years ago, so I'm not sure if @blink1073 would remember why. It did not seem to be necessary for tests to pass as the previous commit worked. |
The code changed slightly 2 years ago but AxesImage objects (such as the artist from imshow) are still always drawn, regardless of the animate setting. I am not sure why this check is needed, but it is still an issue for animations in figures with AxesImage objects. matplotlib/lib/matplotlib/axes/_base.py Lines 3025 to 3029 in 9ced0c0
|
The core of this chases back to #4014 where that check was added to fix tests..... |
ah, but the logic it was replacing goes back to 5e65bbe (2013) when blame stops working (due to that commit splitting up a huge file into three), but it looks like we used to:
The change in #4014 just maintained that behavior. From 2015 there has been some changes in how we do the compositing (it is now handled in a helper that instead of compositing all of the images into to (ignoring zorder) it will composite images into runs). This naming is a bit weird because you could argue all of our drawing is infact compositing, but what is going on here is that we are reducing N I suspect in 2015, we needed to keep holding the images out to not mess with the z-order, but there is a chance it will work now given the other improvements to the image compositing code. diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py
index 6d7336d311..e9ce32ae10 100644
--- a/lib/matplotlib/axes/_base.py
+++ b/lib/matplotlib/axes/_base.py
@@ -3025,7 +3025,7 @@ class _AxesBase(martist.Artist):
if not self.figure.canvas.is_saving():
artists = [
a for a in artists
- if not a.get_animated() or isinstance(a, mimage.AxesImage)]
+ if not a.get_animated()]
artists = sorted(artists, key=attrgetter('zorder'))
# rasterize artists with negative zorder passes tests for me on main. Labeling this as a good first issue (as there is a patch). The remaining work to do is:
|
Good first issue - notes for new contributorsThis issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide. We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR. If something is unclear, please reach out on any of our communication channels. |
Hey, I was trying to figure this out, and I found that the get_rasterized() method returns False for both the plots, but the get_visible() method returns True for both. I've also seen that the objects ln and im are artists in the axes 1 and 2, while the expected behavior should be that it only is in ax1. Im not able to figure out why one is plotting and the other is not. Any help would be greatly appreciated. Have been working on this for quite some time :(
|
Bug report
Bug summary
Setting
animated=True
during a plot call is supposed to make matplotlib artists not be drawn unless explicitly called. SourceWith
plt.plot([1,2,3], animated=True)
, callingplt.show()
shows an empty axes.However,
plt.imshow([[1,2],[3,4], animated=True)
does show an image.I observe this behaviour with both the qt5 and tk backends.
Have I misunderstood something? Or is this a discrepancy?
Code for reproduction
Here is a full example:
Actual outcome

Expected outcome
Two blank axes.
Matplotlib version
print(matplotlib.get_backend())
): Qt5AggThe text was updated successfully, but these errors were encountered: