首页 > 解决方案 > matplotlib.animation - 在曲线上移动点

问题描述

我正在尝试做一个简单的动画:在曲线上移动一个点,但我不太明白我的错误。

有人可以骂我吗?谢谢

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


fig, ax = plt.subplots()
# ax.set_facecolor('black')
x = np.arange(0.0, 10, 0.5)
y = np.arange(10, 20, 0.5)
line =plt.plot(x,y)
dot, =plt.plot([0],[y[0]],'ro', markersize=5)

def init():
    dot.set_data([],[])
    return(dot, )

def animate(i):
    dot.set_data(i, y[i])
    return(dot, )

a = animation.FuncAnimation(fig, animate, init_func=init, frames=np.arange(0.0, 10), interval=50, blit=True)
plt.show()

标签: python-3.xmatplotlib-animation

解决方案


推荐阅读