Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Bug report
Bug summary
FuncAnimation
(as called from a .save() to a movie command), takes significantly longer to complete when passing afigure()
instance type vs aFigure()
one. A lot of testing performed with differently defined animations all show a similar problem, with some tests usingfigure()
can take twice as long.
Code for reproduction
"""A simple `FuncAnimation` example: figure() vs Figure() Performance"""importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlib.animationasanimationfromtqdm.autoimporttqdmimporttimeplt.style.use("ggplot")# set plot stylefig,ax=plt.subplots()# this creates a figure() instancex=np.arange(0,2*np.pi,0.01)line,=ax.plot(x,np.sin(x))defanimate(i):line.set_ydata(np.sin(x+i/10.0))# update the datareturnline,# Init only required for blitting to give a clean slate.definit():line.set_ydata(np.ma.array(x,mask=True))returnline,# Run #1now=time.time()ani_f=animation.FuncAnimation(fig,animate,tqdm(np.arange(200),initial=1),init_func=init,interval=25,blit=True)plt.close()ani_f.save("ani_f.mp4")end=time.time()print(f"Run #1: `FuncAnimation` took{(end-now):.3f}s with `figure()`")# Run #2fig=plt.Figure()# this creates a Figure() instanceax=fig.add_subplot()now=time.time()ani_F=animation.FuncAnimation(fig,animate,tqdm(np.arange(200),initial=1),init_func=init,interval=25,blit=True)plt.close()ani_F.save("ani_F.mp4")end=time.time()print(f"Run #2: `FuncAnimation` took{(end-now):.3f}s with `Figure()`")
Actual outcome
Expected outcome
I expected the same times for both runs: usingfigure()
orFigure()
as input toFuncAnimation
.
Matplotlib version
- Operating system: Windows 10, 10.0.19041
- Matplotlib version: 3.3.2
- Matplotlib backend (
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inline - Python version: 3.8.6
- Jupyter version (if applicable): 6.1.4
All installed viaconda
from aMiniconda3
set up. All packages are installed fromconda-forge
first when available on that channel.