import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.animation as animation # 绘制普通的正弦曲线图 x = np.linspace(-2 * np.pi, 2 * np.pi, 100) y = np.sin(x) fig = plt.figure(tight_layout=True) plt.plot(x, y) plt.grid(ls="--") # 更新数据点的位置 def update_points(num): point_ani.set_data(x[num], y[num]) return point_ani, # 绘制数据点用来运行的正弦曲线 x = np.linspace(-2 * np.pi, 2 * np.pi, 100) y = np.sin(x) fig = plt.figure(tight_layout=True) plt.plot(x, y) point_ani, = plt.plot(x[0], y[0], "ro") plt.grid(ls="-") ani = animation.FuncAnimation(fig, update_points, np.arange(0, 100), interval=100, blit=True) plt.show()
sin-7-2
于 2024-05-13 08:46:07 首次发布