0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
import matplotlib.animation as animation
fig, ax = plt.subplots(figsize=(3,9))
dot, = ax.plot([], [], 'ro')

def init():
    ax.set_xlim(0,1)
    ax.set_ylim(0,3)
    return

def gen_dot():
    for i in range(len(list_x_y)):
    newdot = list_x_y[i]
    yield newdot

def update_dot(newd):
    dot.set_data(newd[0],newd[1])
    return dot

ani = animation.FuncAnimation(fig, update_dot, frames = gen_dot, interval = 100, 
init_func=init)
ani.save('Steps.gif',writer='imagemagick',fps=24)
plt.show()

Hey Guys, So I was trying to create an animation mimicking a real person walking a treadmill with the code shown above. The thing is, I need a variable time interval so that the person is not working at a constant speed, which is not realistic at all.


I figured that probably animation function does not support a varied time interval functionality so I tried using a For loop and get a time interval list such that each time in the for loop it will sleep for a specific amount of time and continue...However, JupyterNotebook will not refresh the frames as I intended it to be, creating a static image in the end of the period...Is there any way I can create a gif with varied time interval? I think maybe I can save all the frames and use imageio to create a gif...But does imageio take varied time interval as input as well? I'm struggling with this problems for hours...Any help would be appreciated. Thanks!

  • ImageMagick does not support variable delays. So try adding duplicate frames to slow things down where you need them slower than your fastest time interval, i.e. delay value. Alternate to duplication would be to add new interpolated frames using some morphing. – fmw42 Oct 01 '18 at 01:14
  • Actually I think I can use a loop to update frames? But somehow if I do so, Jupyter notebook will wait till the entire loop to finish and show me the final plot. Is there a way that I can actually see the updated frames in real-time such time each frame will update using sleep function? I tried canvas.draw() seems not be able to working... Thanks! – Herr Günther Oct 01 '18 at 02:50

0 Answers0