Skip to content
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

plt.text object updating incorrectly with blit=False #6670

Closed
snelltheta opened this issue Jun 30, 2016 · 5 comments
Closed

plt.text object updating incorrectly with blit=False #6670

snelltheta opened this issue Jun 30, 2016 · 5 comments

Comments

@snelltheta
Copy link

snelltheta commented Jun 30, 2016

I have a FuncAnimation that is using a plt.text object to display the i-th column of my time_data array.
It looks great when blit=true, but when I save the file as a movie or make blit=false, the text overwrites itself. Since my goal is making a movie, I wish there was a way to make blit=true for the save function.

blit=True

blit=True

blit=False

blit=False, and also a movie

Basically, the code is this

#raw_data is a 2-D array where the 0th column is the data to display
def init():
    line.set_data([], [])
    return line,
def animate(i):
    x = np.linspace(lower_bound,upper_bound,upper_bound-lower_bound)
    y = raw_data[i,lower_bound:upper_bound]
    line.set_data(x, y)
    time_stamp=plt.text(0.5,0.1,time_data[i],verticalalignment='center',
                        horizontalalignment='left',
                        transform=ax.transAxes,fontsize=15)
    return time_stamp, line,
    anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=200, interval=110, blit=True)

    anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])

MPL version 1.5.2rc2
Installed from Debian apt repository

@efiring
Copy link
Member

efiring commented Jun 30, 2016

I think you need to treat the text element the same way that you treat the line: initialize and return it in your init, and then call time_stamp.set_text(time_data[i]) in your animate.

@dopplershift
Copy link
Contributor

I agree with @efiring 's assessment--the blit is masking the fact that text isn't being included in the animation. Instead what's happening is a new Text instance is being created for every frame.

@snelltheta
Copy link
Author

That was it!

@guaracheitor
Copy link

guaracheitor commented Jan 11, 2018

Hi snelltheta, I think that I have the same problem, but I can't to figure out the solution. Can you show me the final code? Thanks.

@guaracheitor
Copy link

Finally I made it work! :) I think that this example is perfect to understand this problem --> https://matplotlib.org/examples/animation/double_pendulum_animated.html
Tnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants