【发布时间】:2021-05-07 13:55:27
【问题描述】:
我想使用matplotlib.annimation 顺序绘制数据点并绘制已知的垂直线。
我目前拥有的如下:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
x = np.arange(len(data))
y = data
fig = plt.figure()
plt.xlim(0, len(data))
plt.ylim(-8, 8)
graph, = plt.plot([], [], 'o')
def animate(i):
# line_indicies = func(x[:i+1])
graph.set_data(x[:i+1], y[:i+1])
# then I would like something like axvline to plot a vertical line at the indices in line indices
return graph
anim = FuncAnimation(fig, animate, frames=100, interval=200)
# anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
plt.show()
我想绘制从 animate 函数中的 cmets 中描述的函数输出的垂直线。
随着处理更多数据点,线条可能会发生变化。
【问题讨论】:
标签: python matplotlib matplotlib-animation