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

Skip to content

Wrong path in the html file when running save function in FuncAnimation #9960

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

Closed
EricPwg opened this issue Dec 8, 2017 · 2 comments
Closed
Labels
status: inactive Marked by the “Stale” Github Action topic: animation
Milestone

Comments

@EricPwg
Copy link

EricPwg commented Dec 8, 2017

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
"""
from os import system
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
fig.set_tight_layout(True)

x=list(range(10))
y = x
p, = ax.plot(x, y)

def update(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 = []
    for j in range(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

<script language="javascript">
  /* Instantiate the Animation class. */
  /* The IDs given should match those used in the template above. */
  (function() {
    var img_id = "_anim_img61ae9140e79d48909289ca13448775e9";
    var slider_id = "_anim_slider61ae9140e79d48909289ca13448775e9";
    var loop_select_id = "_anim_loop_select61ae9140e79d48909289ca13448775e9";
    var frames = new Array(5);
    
  for (var i=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 = new Animation(frames, img_id, slider_id, 200.0,
                                 loop_select_id);
    }, 0);
  })()
</script>

Expected outcome
Please note the path in the for loop.

<script language="javascript">
  /* Instantiate the Animation class. */
  /* The IDs given should match those used in the template above. */
  (function() {
    var img_id = "_anim_img61ae9140e79d48909289ca13448775e9";
    var slider_id = "_anim_slider61ae9140e79d48909289ca13448775e9";
    var loop_select_id = "_anim_loop_select61ae9140e79d48909289ca13448775e9";
    var frames = new Array(5);
    
  for (var i=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 = new Animation(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
@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 27, 2023
@tacaswell
Copy link
Member

I think the example should have been

    anim.save('anim/line.html', dpi=80, writer='html')

However, the output is now

  for (var i=0; i<5; i++){
    frames[i] = "line_frames/frame" + ("0000000" + i).slice(-7) +
                ".png";
  }

This was reported a second time as #23581 and was fixed via #24482 which was included in 3.6.3.

@tacaswell tacaswell added this to the v3.6.3 milestone Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: inactive Marked by the “Stale” Github Action topic: animation
Projects
None yet
Development

No branches or pull requests

3 participants