Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Description
Bug report
Bug summary
In the below code, when using save function, it will create a html file named "line.html" and a folder named "line_frames" in the inner folder "anim".
The save function run will usually. But if the path of the file is in the inner folder just like this case, the frames path in the script tag of the html file will be wrong.
Only when changing the path myself, the script can run successfully.
I think there might be a bug when creating html file.
Code for reproduction
# -*- coding: utf-8 -*-"""Created on Sat Dec 9 02:38:37 2017@author: user"""fromosimportsystemimportnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.animationimportFuncAnimationfig,ax=plt.subplots()fig.set_tight_layout(True)x=list(range(10))y=xp,=ax.plot(x,y)defupdate(i):label='timestep {0}'.format(i)print(label)# Update the line and the axes (with a new xlabel). Return a tuple of# "artists" that have to be redrawn for this frame.yi= []forjinrange(10):yi.append(j**i)p.set_ydata(yi)ax.set_xlabel('x^'+str(i))return (p,ax)if__name__=='__main__':system('mkdir anim')anim=FuncAnimation(fig,update,frames=np.arange(0,5),interval=200)anim.save('anim/line.html',dpi=80,writer='imagemagick')
Actual outcome
Please note the path in the for loop.
# The script tag in the file ./anim/line.html<scriptlanguage="javascript">/* Instantiate the Animation class. *//* The IDs given should match those used in the template above. */(function(){varimg_id="_anim_img61ae9140e79d48909289ca13448775e9";varslider_id="_anim_slider61ae9140e79d48909289ca13448775e9";varloop_select_id="_anim_loop_select61ae9140e79d48909289ca13448775e9";varframes=newArray(5);for(vari=0;i<5;i++){frames[i]="anim/line_frames/frame"+("0000000"+i).slice(-7)+".png";}/* set a timeout to make sure all the above elements are created before the object is initialized. */setTimeout(function(){anim61ae9140e79d48909289ca13448775e9=newAnimation(frames,img_id,slider_id,200.0,loop_select_id);},0);})()</script>
Expected outcome
Please note the path in the for loop.
<scriptlanguage="javascript">/* Instantiate the Animation class. *//* The IDs given should match those used in the template above. */(function(){varimg_id="_anim_img61ae9140e79d48909289ca13448775e9";varslider_id="_anim_slider61ae9140e79d48909289ca13448775e9";varloop_select_id="_anim_loop_select61ae9140e79d48909289ca13448775e9";varframes=newArray(5);for(vari=0;i<5;i++){frames[i]="line_frames/frame"+("0000000"+i).slice(-7)+".png";}/* set a timeout to make sure all the above elements are created before the object is initialized. */setTimeout(function(){anim61ae9140e79d48909289ca13448775e9=newAnimation(frames,img_id,slider_id,200.0,loop_select_id);},0);})()</script>
Matplotlib version
- Operating system: Windows7
- Matplotlib version: 2.1.0
- Matplotlib backend (
print(matplotlib.get_backend())
):Qt5Agg - Python version: 3.6.3
- IDE: Spyder@Anaconda
- Other libraries: IPython 6.1.0