Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create a reference example for set_data and friends #19520

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

Open
ianhi opened this issue Feb 16, 2021 · 5 comments
Open

Create a reference example for set_data and friends #19520

ianhi opened this issue Feb 16, 2021 · 5 comments
Labels
Documentation: user guide files in galleries/users_explain or doc/users Documentation topic: animation

Comments

@ianhi
Copy link
Contributor

ianhi commented Feb 16, 2021

Problem

It's tricky to learn that you should use set_data when animating. When i first got into this I was essentially doing:

for t in range(timepoints):
    ax.imshow(data[t])

which is bad news for performance. I fortunately had someone around to tell me to use set_data but lacking that I think it would have taken me a lot longer to figure out.

However, even after figuring that out it's not all smooth sailing. I was tripped up for quite awhile on how to animate a scatter plot as it uses set_offsets instead of set_data. There can also be other complications see for example #18401.

Suggested Improvement

Include a reference style example in the animation section of the gallery that goes over how to animate all the possible animatable artists (set_data, set_offsets, etc...). Or at least all of the artists that get returned from pyplot functions. Ideally the example would use the artists created from pyplot(or equivalent ax) functions as this is how I imagine most people will create the artists for their animations.

For reference I brought this up on gitter, but gitter just crashed :(

Matplotlib version

  • Matplotlib documentation version: any
@timhoffm
Copy link
Member

This reference example should also mention the animated property and blitting. For reference, see #19533.

@ianhi
Copy link
Contributor Author

ianhi commented Feb 24, 2021

Just to note it would also be great to include the 3d animations as well. As set_3d_properties can be a bit mysterious.

@bkestelman
Copy link

I would add that ideally set_data should be part of the API for the other types of plot (scatter, bar, etc.) as well. It's very confusing that they each have their own method. Moreover, some of the other methods are not as flexible, for example bar's set_heights cannot be used to add data that would create new bars, as far as I know.

I'm curious what the reason is for excluding set_data from the scatter and bar API's. Would it be possible to add it?

@tacaswell
Copy link
Member

@bkestelman The API is the way it is for "historical reasons" as each of the Artists grew organically. The problem you are identifying actually run much deeper as each Artist stores its data is a slightly different way which makes writing a generic set_data difficult. Because each Artist requires a different set of data (with different expected sizes etc) even if we had set_data on each artist, the signatures would need to be very different (for example, im.set_extent is as important as set_data for images and we probably do not want to roll them into one).

On the bright side, addressing this problem is one of the goals of the first two grants from CZI (supporting research) and a NASA gant (which will be starting shortly) to implement it. See https://github.com/matplotlib/2020-NASA-ROSES-E7 for more details on what we are planning to do over the next 3 years.

@bkestelman
Copy link

@tacaswell Thanks for the informative reply and the link. I'll keep an eye on those plans and see if I can contribute anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: user guide files in galleries/users_explain or doc/users Documentation topic: animation
Projects
None yet
Development

No branches or pull requests

5 participants