-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Animations & Object Persistence #1656
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
This is known and @dopplershift and I have discussed this particular issue offline many times before. We have thought of your idea before, but I forget why we dismissed it. There are peculiarities/features of animation objects that doesn't quite lend itself to this approach. Do you remember the reasons, Ryan? |
If memory serves correctly (and I'm older now, so that's no guarantee), my aim was to avoid any modification of the rest of matplotlib to support this. A secondary "issue" is that a figure can have more than one animation, so the figure would likely need a list of animations. If @jakevdp's extensive use of the module is any indication, this module seems to be getting good uptake and the overall approach seems like it was the right one--I'm more inclined now to make modifications to the broader matplotlib code base if they make it even easier to make animations. Mostly however, my objection was and still (somewhat) is code purity. I personally feel it's a little silly to do this just to avoid the (correct) code of having to save a reference to the object manually. For instance, if you create a Line2D instance by hand, it's not automatically added to an axes, and if you don't save a reference, POOF! Also, it seems odd for the figure to assume ownership of the animation when it doesn't touch it otherwise at all. However, I do recognize that this seems to be somewhat of a pain point, or at least a common gotcha, and should be addressed. So I'm not really sure what I'm arguing here. There are no technical hurdles with adding an |
Interesting thoughts. From my perspective, it would seem much more natural to do something like fig.add_animation(anim_func) rather than the current anim = animation(fig, anim_func) The class method version would probably not be more than just a wrapper around the current function, but it would be more apparent that it's actually meant to add something to the figure class. It would bring up some questions, though: for example, if you call |
I agree the former fits better with matplotlib's typical, minimal OOP API. However, we have two different animation classes (
or
I'm not particularly keen on either of those. I also agree about What about:
? |
I agree that all those options are a bit kludgy. Regarding the last option: because the fig.add_animation(FuncAnimation(fig, *args)) Maybe the simplest thing to do would be to keep the syntax of animations the same as what it is now, but simply add a line to the animation constructor which does something like fig.animations.append(self) That would maintain full backward compatibility, would be very clean, and would sufficiently address the problem of object persistence. As a bonus, you'd be able to introspect each figure and see any animations that are attached to it. |
Just a note on the "code purity" thing. Creating an "isolated" Line2D is different because you don't specify the axes or figures when doing so. In the code |
What's the latest on this? |
Looking at it with really fresh eyes (2 years later), I think @jakevdp 's last suggestion, of just adding to a My only minor concern here is that we're taking a one-way coupling ( (For the record, I still don't consider this a problem, since I'm not volunteering to do it, but adding the |
So, I noticed an interesting use case for this in writing tests. Currently, when doing image comparison tests. A test function is written to make a plot, and a decorator grabs that figure and saves it as an image before comparing it. This figures are grabbed by these lines. If the figure had knowledge of the animation, then it would be easy to grab the animation and save it for comparison. Alternatively, the test function could return the animation so that the decorator could pick it up. #11839 |
Untagged "good first issue", given that it's really a design problem now (and we already rejected two PRs implementing the "obvious" solution). |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
I think we've had this conversation a few times in favour of asking people to keep their animations persistent. Yes, people are still sometimes confused about this, but the docs have a lot of pointers that explain the right way to do this, so I think it's OK to close this. |
Unlike other plotting operations, if you create an animation and do not store it in a persistent variable, it will fail.
So, for example,
will work, but changing the final lines to
(i.e. not creating a variable to store the animation) leads to a quiet failure.
I think the problem is because the figure does not store a reference to the animation object, python's garbage collection removes it if it is not explicitly stored.
Probably the best way to address this would be to add an
animation
attribute to theFigure
class, such that any animation will store a pointer to itself in its associated figure.I think this is a pretty easy fix, but I'm just wondering if there are any other details to be aware of when adding something like this.
The text was updated successfully, but these errors were encountered: