GIF in python from an existing vector

Hello! I want to make a GIF from data of a certain vector. The solutions for such that I found, serve when the vector is populated within the update function itself. I have tried to emulate an easier case so that it is possible to see what is happening and later implement in the code in question. Now the problem is that it is presenting "index error". Below, my code.

import numpy as np  
import matplotlib.pyplot as plt  
from matplotlib.animation import FuncAnimation, PillowWriter  
%matplotlib notebook 
fig, ax = plt.subplots()  
x, y = [], [] 
ln1, = plt.plot([], [], 'ro')  
def init():  
  ax.set_xlim(0, 10)  
  ax.set_ylim(0, 10)  

teste=[3,5,8,2]
def update(i,teste):  
  x.append(i)  
  y.append(teste[i])
  ln1.set_data(x, y)  
ani = FuncAnimation(fig, update, np.linspace(0, 5, 4), init_func=init, fargs=teste)  
plt.show()
writer = PillowWriter(fps=25)  
ani.save("demo_sine3.gif", writer=writer) 

My goal is to create a gif from the graph of each point. That is, one frame for (0,3), another for (0,3)+(1,5), another for (0,3)+(1,5)+(2,8), other for (0,3)+(1,5)+(2,8)+(3,2). I say this because in one of my attempts, I got only the graph with all the points, rather than a frame for each concatenate.

 0
Author: sãojorge, 2020-06-09