summaryrefslogtreecommitdiff
path: root/vis/animation/line_plot_ani.py
blob: 21ed9cda581df486c9de8e24c45b26a71dad8331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = ax.plot([], [], 'ro')

ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)


def init():
    # print('init')
    ax.set_xlim(0, 2*np.pi)
    ax.set_ylim(-1, 1)
    return ln,


def animate(i):
    # print('animate', i)
    xdata.append(i)
    ydata.append(np.sin(i))
    ln.set_data(xdata, ydata)
    return ln,


ani = FuncAnimation(fig,
                    animate,
                    frames=np.linspace(0, 2*np.pi, 128),
                    # init_func=init,
                    blit=True
                    )
plt.show()