我正在尝试用 2 个相等的数组制作一个简单的折线图。我在网上看过一些指南,但老实说,我不确定我在这里做什么,我是否接近解决方案?
我正在寻找这个:https ://miro.medium.com/max/1126/1*j0LxVQPbwtQDpL17TH9gZw.gif
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([6,9,12,42,50,62,76,82])
fig = plt.figure()
ax = plt.axes(xlim=(1, 8), ylim=(6, 82))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_ydata(x[i:])
line.set_xdata(y[i:])
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
plt.show()