title: Live plotting from CSV file with matplotlib.animation - Data drawn to first entry error
body: <p>I am attempting to plot data from a sensor that is continuously being written to a CSV file. While successful in creating a live plot, each new data entry creates an additional line that extends to the first data entry. See Below:</p>
  <p>The Python 3.4 Script:</p>
  <pre><code>import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import time
  import datetime as dt
  import csv
  
  
  
  fig = plt.figure()
  ax1 = fig.add_subplot(1,1,1)
  x=[] ; y1=[]; y2=[]; y3=[]
  def animate(i):
      with open( 'data_log.csv', 'r') as csvfile:
          
          alphasensefile = csv.reader(csvfile, delimiter = ',')
          next(alphasensefile, None)
          next(alphasensefile, None)
          next(alphasensefile, None)
  
          for column in alphasensefile:
              a = dt.datetime.strptime((column[0]), '%H:%M:%S')
              x.append((a))
              y1.append(column[1])
              y2.append(column[2])
              y3.append(column[3])
  
  
  
  
      
      ax1.clear()
      ax1.plot(x,y1)
  ani = animation.FuncAnimation(fig, animate, interval=1000)
  
  plt.show()
  </code></pre>
  <p>Running this script collects sensor data and records it to a CSV file. Every data entry recorded live from that start draws an additional line that goes to the first data entry point. Like so:</p>
  <p><img src="https://i.stack.imgur.com/1Ci3A.png" alt="Figure 1" /></p>
  <p>if I open the file while the sensor is not recording, only the last data entry is linked to the first point like so:</p>
  <p><img src="https://i.stack.imgur.com/2gjb6.png" alt="Figure 2" /></p>
  <p>Data is recorded to the CSV file like so:</p>
  <blockquote>
  <p>PM Data Recorded: 23 03 2018</p>
  <p>Time, PM 1, PM 2.5, PM 10</p>
  <p>16:12:10, 0.1173, 0.1802, 3.2022</p>
  </blockquote>
  <p>Any thoughts to why this is occurring?</p>