title: Matplotlib Live Update Graph
body: <p>Below is a sample code taken from this website:
  <a href="http://pythonprogramming.net/python-matplotlib-live-updating-graphs/" rel="nofollow noreferrer">http://pythonprogramming.net/python-matplotlib-live-updating-graphs/</a></p>
  
  <pre><code>import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import time
  
  fig = plt.figure()
  ax1 = fig.add_subplot(1,1,1)
  
  def animate(i):
      pullData = open("sampleText.txt","r").read()
      dataArray = pullData.split('\n')
      xar = []
      yar = []
      for eachLine in dataArray:
          if len(eachLine)&amp;gt;1:
              x,y = eachLine.split(',')
              xar.append(int(x))
              yar.append(int(y))
      ax1.clear()
      ax1.plot(xar,yar)
  ani = animation.FuncAnimation(fig, animate, interval=1000)
  plt.show()
  </code></pre>
  
  <p>the data are comma delimited text file looks something like this:</p>
  
  <pre><code> DD/MM/YYYY H:M, 10.0, 20.0
   DD/MM/YYYY H:M, 12.0, 22.0
  </code></pre>
  
  <p>This is a snippet of how it looks like, i got thousands of these lines in my file.</p>
  
  <p>How can i make the code above to fit in here since i have two lines graph rather than one line ?</p>
  
  <pre><code>linematchregex = re.compile('(\d+/\d+/\d+ \d+:\d+),(\d+\.\d+)')
  
  startTime = datetime.strptime(raw_input('please enter start time :'), '%d/%m/%Y %H:%M')
  endTime   = datetime.strptime(raw_input('please enter end time :') , '%d/%m/%Y %H:%M')
  
  with open(r'sample.txt', 'r') as strm:
      strm.next()
      t, y, temp = zip(*[p for line in strm for p in linematchregex.findall(line)])
  t = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in t ]
  y = [float(x) for i,x in enumerate(y) if startTime&lt;=t[i]&lt;=endTime]
  temp = [float(x) for i,x in enumerate(temp) if startTime&lt;=t[i]&lt;=endTime]
  
  t = [x for x in t if startTime&lt;=x&lt;=endTime]
  fig = plt.figure()
  fig.subplots_adjust(top=0.80)
  ax1 = fig.add_subplot(1, 1, 1, axisbg='white')
  ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M'))
  ax2 = ax1.twinx()
  ax1.plot(t, y, 'c', linewidth=3.3)
  ax2.plot(t, temp, linewidth=3.3)
  
  plt.show()
  </code></pre>