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
"""
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