title: Python Matplotlib- chart can't update itself
body: <p>I'm trying to make graph that would plot real time stock prices. My code is shown below.</p>
  
  <pre><code>import urllib.request
  from bs4 import BeautifulSoup
  import matplotlib.pyplot as plt
  import datetime
  import time
  
  t = urllib.request.urlopen('http://finance.yahoo.com/quote/YHOO/history?ltr=1')
  the = t.read()
  soup = BeautifulSoup(the, 'html.parser')
  timeticks = []
  x = []
  prices = []
  i = 1
  
  while 1:    
  
      n = soup.find('span',class_="Fw(500) D(ib) Fz(42px)")     
      time.sleep(1)
      plt.cla()
      nf = float(n.string)
      prices.append(nf)
  
      now= datetime.datetime.now()
      times=('%02d:%02d:%d'%(now.hour,now.minute,now.second))
      timeticks.append(times)
      x.append(i)
  
      plt.xticks(x,timeticks)
      plt.plot(x,prices,"b-")
      plt.xlabel("Time")
      plt.ylabel("Stock prices")
      plt.title("Yahoo's Stocks")
      plt.show()
      i +=1
  </code></pre>
  
  <p>When I run the code, I get a figure and when I close it, another figure with another plotted point shows up. What I want to do is keep the first figure update it for every point shown every one second. Is there a way to do this? (By the way, I do know that there is a yahoo finance package. Before I finished this much of my code, I didn't know, so I used Bs4.)</p>