title: Animate scatter plot with points of different colors and size each
body: <p>I have real time data generated by a script which generate x,y1,y2 values where x is sequential and<br>
  -10 &lt; y1 &lt; 10  -10 &lt; y2&lt; 10. This is then sent to a .csv file.</p>
  
  <p>I need to display the y1,y2 values in a scatter plot where I only see the last 3 inputs. I also want to update this plot in real time using FuncAnimation. </p>
  
  <p>The idea is that seeing the 3 dots on screen, each value should be recognizable by date.
  The last one(i) could be red and big size, the (i-1) yellow and medium size and the(i-2) green and small size.</p>
  
  <p>data_gen.py:</p>
  
  <pre><code>
  import csv
  import random
  import time
  X = 0
  Y = 0
  Y2 = 0
  fieldnames = ["X", "Y", "Y2"]
  
  with open('data.csv', 'w') as csv_file:
      csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
      csv_writer.writeheader()
  
  while True:
      with open('data.csv', 'a') as csv_file:
          csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
  
          info = {
              "X": X,
              "Y": Y,
              "Y2": Y2
          }
  
          csv_writer.writerow(info)
          print(X, Y, Y2)
  
          X += 1
          Y = random.randint(-10, 10)
          Y2 = random.randint(-10, 10)
      time.sleep(1)
  </code></pre>
  
  <p>Test.py:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import matplotlib.animation as animation
  import pandas as pd
  
  def main():
  
      numframes = 100
      numpoints = 10
      color_data = np.random.random((numframes, numpoints))
      plt.style.use('fivethirtyeight')
      data = pd.read_csv('data.csv')
      x,y1,y2 = data['X'],data['Y'], data['Y2']
  
      y1 = y1[-3:]
      y2 = y2[-3:]
      x_ = x.to_numpy()
      y1_ = y1.to_numpy()
      y2_ = y2.to_numpy()
      y1_ = y1_.reshape(-1, 1)
      y2_ = y2_.reshape(-1, 1)
      y_tot= np.hstack((y1_,y2_))
  
      fig = plt.figure()
      scat = plt.scatter(y1_, y2_,color='red')
  
      axes = plt.gca()
      axes.set_xlim(-14, 14)
      axes.set_ylim(-14,14)
  
      ani = animation.FuncAnimation(fig, update_plot,interval=1000, frames=range(numframes),fargs=(color_data, scat))
      plt.show()
  
  def update_plot(i, data, scat):
      data = pd.read_csv('data.csv')
      x,y1,y2 = data['X'],data['Y'], data['Y2']
      y1 = y1[-3:]
      y2 = y2[-3:]
  
      x_ = x.to_numpy()
      y1_ = y1.to_numpy()
      y2_ = y2.to_numpy()
      y1_ = y1_.reshape(-1, 1)
      y2_ = y2_.reshape(-1, 1)
      y_tot= np.hstack((y1_,y2_))
  
  
      '''Set de values'''
      scat.set_offsets(y_tot)
      '''Set de color'''
      # scat.set_array(data[i])
      '''Set de tamaño'''
      # scat.set_sizes(scat.get_sizes()*2)
      return scat,
  
  main()
  </code></pre>
  
  <p>I don't know how to proceed. As now, I can display the last 3 updated values generated in the .csv but I can't tell which one is the last.</p>
  
  <p>should I do something like</p>
  
  <pre><code>plt.plot(y1_[0],y2_[0],'r',y1_[1],y2_[1],'y',y1_[2],y2_[2],'g')
  </code></pre>
  
  <p>inside the Animation function?</p>
  
  <p>Thank you!</p>