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>
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
github-actions commented on Apr 27, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
tacaswell commented on Apr 27, 2023
I think the example should have been
anim.save('anim/line.html', dpi=80, writer='html')However, the output is now
This was reported a second time as #23581 and was fixed via #24482 which was included in 3.6.3.