-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Animation Tutorial #24274
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
Animation Tutorial #24274
Conversation
What sort of feedback would be helpful at this stage? |
I don't think I've added that much right now to have any suggestions particularly, but just in general, is the type of animation okay for the plots? I was thinking to keep them very simple and distraction-free so as to focus more on the process of animating rather than the data that it animates. |
Yeah if anything I'd suggest going even simpler and just using sin/cos/unit circle so you can remove the data generation functions |
@story645 can you take a look at this? I think I have this as a first draft and would appreciate feedback! I had a question too, actually. I'm not sure why the Lines2D animation is not showing up correctly. I tried saving it locally as .html and that seems to be working fine but for some reason, it isn't working correctly in the docs. |
@story645 thanks for the feedback! I've updated most of the things. Let me know if there are more things to change :) |
Something's still wrong with the line plot though. Working on it. |
The animation for Lines2D was not showing the animation properly but was showing just the final frame. Adding an init function resolved this issue and the animation appears correctly now.
Okay, the line plot seems to be working now. For some reason, adding an |
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.
I think the bones are awesome! I also think this is in large enough scope that it needs a second review.
I left it out of my outline so my mistake, but I think it'd be useful to briefly go through the various methods on animation with possibly putting to_jshtml
and to_html_video
at the bottom as part of a saving section
edit: also my bias for the line is something simple unless you can explain what the deleting values is about. Alternatively, I was able to remove the init by pulling the axes setting outside the init ax.set(ylim=(-1.1, 1.1), xlim=(0, 5))
fig, ax = plt.subplots() | ||
rng = np.random.default_rng() | ||
t = np.linspace(-4, 4, 400) | ||
a, b = 3, 2 | ||
delta = np.pi / 2 | ||
|
||
scat = ax.scatter(np.sin(a * t[0] + delta), np.sin(b * t[0]), c="b", s=2) |
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.
I really like reusing an example and showing a different method of doing the same thing, so I'd suggest then you reuse scatter. Or pick something that's really well suited to artist animation, but I'm honestly not sure what that would be.
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.
"Animating Markers" and "Animating Images" are structurally very similar to "Animating Lines". IMHO they don't explain something new (other than you use different set_*
methods to manipulate the 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.
Yes, but the different set_* methods is kind of the point, unless there's a different way to structure this so it's clear that the key to animation is finding that artists set_data
equivalent -> maybe a table?
I changed it to the simple example you linked and that works for some reason, so let me put that instead! |
Forgot that the decay example doesn't have explicit frames but the docs save out to 100 and that might be why things are inconsistent. |
Ah okay. Yeah, that might be the case. Thanks for that! |
@story645 I changed to an example that shows a 2d gaussian pdf with increasing covariance (kind of a raindrop effect). I feel that this shows the changes in the image in a better way and also allows the example to not be extremely convoluted. This also allows reusing the same in ArtistAnimation. Let me know, thanks! |
Wondering if for the artist animation you should add an additional artist to each list? Maybe a marker that moves across the page or something? |
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.
Thanks for pinging me, I hope these are minor changes.
I think this is a great starting base that has all the important bits.
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.
It exists! I think this has all the important bits written out in a way that's more user friendly than the API docs and isn't overwhelming 😁
I'm not sure if this is significant enough to need a 2nd review.
Hey folks, since this is documentation my plan is that if there are no reviews over the weekend then I'll merge Monday if there are no objections. |
Thanks @QuLogic! That should fix all of the comments. |
I squash merged as it's unlikely we need all 29 commits preserved. |
* First version of animation tutorial * Simplify examples by removing data gen functions * Add tutorial text * Format to agree with flake8 * Update tutorial and scatter example * Fix example for line animation The animation for Lines2D was not showing the animation properly but was showing just the final frame. Adding an init function resolved this issue and the animation appears correctly now. * Change to simpler line animation example * Change headings and update set_offsets description * Change writer type to pipe-based from standard * Update saving animation section * Add new example for images and ArtistAnimation * Remove unused variables * Correct type of animation class * Remove unused variable * Correct wrong correction * Update ArtistAnimation example to use bar chart * Barchart race example for ArtistAnimation * Change FuncAnimation to have one general guideline * Add a table for set methods for example artists * Add plotting method, return artist type table * Reword to avoid confusion * Reposition note about pipe based writers * Change color and don't sort bar chart * Remove animation code in save animation section * Change inline codeblocks to clear CI * Make small corrections as per code review * Remove :class: from links * Set the animation range so that it loops * Update to better animation range for scatter
PR Summary
A one-stop tutorial that covers all the major points of creating an animation using the
matplotlib.animation
module. (Reference issue: #24228 by @story645)PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).