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

Skip to content

func animation warning changes #11829

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

Merged
merged 1 commit into from
Aug 9, 2018

Conversation

fredrik-1
Copy link
Contributor

@fredrik-1 fredrik-1 commented Aug 9, 2018

Another pr from #11792

The example code on that issue raised on error on master but not on v2.2.2. The reason where that the animation function returned None.

This pr change the order of some of the code to avoid the error and just test for the return value when it is needed when blit is True.

I am not sure if this is necessary or if the test is in the right place but the behavior is better now than before.

The animation function should return an iterative according to the documentation but I think that it is unnecessary to test for it and raise on error or warning when it is not necessary for the code to work.

@ImportanceOfBeingErnest
Copy link
Member

Well spotted, @fredrik-1. I do however fear that people might not understand the motivation and implication.

So the following code works fine on 2.2.2

import matplotlib.pyplot as plt
import matplotlib.animation

fig, ax = plt.subplots()
line, = ax.plot([0,10])

def animate(i):
    line.set_ydata([i, 10-i])
    
ani = matplotlib.animation.FuncAnimation(fig, animate, 10)
plt.show()

Due to a change in #11370 the same code now breaks in master with

TypeError: 'NoneType' object is not iterable

This is due to the animating function not returning an iterable of artists.

According to the documentation such animating function should indeed return an iterable of artists, however there is in principle no such need if blit=False (the default) is used. This leads to the construct from above being widely spread.

If a version with #11370 in is now being released, it will break a lot of people's codes.

Options:

  • Make it explicit that from now on you really need to return an iterable of artists. This would at least get a what's new entry. It would also need a proper Error message to tell people what to do.
  • Be forgiving about not returning any artists (just as it's always been). In this case the fix proposed in this PR may be useful.

I would consider this release critical for 3.0.

@tacaswell tacaswell added this to the v3.0 milestone Aug 9, 2018
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 9, 2018
@tacaswell
Copy link
Member

For 3.0 this fix is the pragmatic change to prevent back-compatibility issues.

For 3.1 we may want to start warning if no artists are returned, but that should happen in a different PR.

@ImportanceOfBeingErnest
Copy link
Member

For 3.1 we may want to start warning if no artists are returned

although it is a bit questionable why one would force users to add some useless line like

def animate(i):
    line.set_ydata([i, 10-i])
    return fig.patch,

just to prevent some warning.

@dopplershift dopplershift merged commit f61358a into matplotlib:master Aug 9, 2018
@dopplershift
Copy link
Contributor

Until I finally finish refactoring the blitting code so that it's more reliable, I think it's fine to only care about having the callback return artists for the blitting path.

@t-makaro
Copy link
Contributor

t-makaro commented Aug 9, 2018

As say this as someone who just spent the last month writing a library that wraps funcanimation. It is a really bad idea to require that the callback has returns artists (if blitting is false).

My library is built on the concept "blocks" while most of my blocks return artists some don't. (which means I might return a list of artists with some NoneTypes though I can issue a warning if blitting is true and certain blocks are used)

Animating things in matplotlib can be very difficult. It is very common for people to do:

def animate(i):
    ax.clear()
    #re-plot everything

This is a common tactic for pcolormesh despite there being a proper way to update the data, and for some types of plots (like pie charts), it's the only reasonably easy way. Requiring it to return artists just make's it a lot harder for people.

I'm seriously against requiring the callback to return artists in the future (if blitting is false). Totally for an error if blit is true.

@tacaswell
Copy link
Member

So that seems to be pretty conclusive that we do not want to start warning on no returns for 3.1 !

@fredrik-1 fredrik-1 deleted the func_animation_warning branch August 10, 2018 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: animation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants