diff options
| author | zhang <zch921005@126.com> | 2022-10-30 23:13:29 +0800 |
|---|---|---|
| committer | zhang <zch921005@126.com> | 2022-10-30 23:13:29 +0800 |
| commit | 1b105470efecf90fe1a7e153191835cf0c4dfb19 (patch) | |
| tree | aeba0fb736e4e9d9e0f050117ca317fab1f2f37e /vis/animation/line_plot_ani.py | |
| parent | b5c7383a7abfa87396bf585b789c9e0474e12652 (diff) | |
multiple line plots
Diffstat (limited to 'vis/animation/line_plot_ani.py')
| -rw-r--r-- | vis/animation/line_plot_ani.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vis/animation/line_plot_ani.py b/vis/animation/line_plot_ani.py new file mode 100644 index 0000000..21ed9cd --- /dev/null +++ b/vis/animation/line_plot_ani.py @@ -0,0 +1,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() + |
