Skip to content

Create a reference example for set_data and friends #19520

Open

Description

@ianhi

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

Activity

  1. timhoffm commented on Feb 17, 2021

    @timhoffm
    Member

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

  2. ianhi commented on Feb 24, 2021

    @ianhi
    ContributorAuthor

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

  3. bkestelman commented on Nov 26, 2021

    @bkestelman

    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?

  4. tacaswell commented on Nov 26, 2021

    @tacaswell
    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.

  5. bkestelman commented on Nov 26, 2021

    @bkestelman

    @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions