title: Matplotlib Basemap Plotting Lat/Lons
body: <p>I cannot for the life of me figure out how to animate points (earthquake epicenters) on a Matplotlib basemap plot, using the animation function.  I have tried implementing <a href="https://stackoverflow.com/questions/21207513/matplotlib-basemap-animation">this</a> example code into my script, but all my points plot at once.  It may have something to do with my function and the for loop within the function.  Any thoughts?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#!/usr/local/bin/python
  from mpl_toolkits.basemap import Basemap
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import numpy as np
  
  fig = plt.figure()
  
  
  #Build the basemap
  antmap = Basemap(projection='spstere', boundinglat=30, lon_0=-60, resolution='f')
  antmap.drawcoastlines(color='black', linewidth=0.15)
  antmap.bluemarble()
  
  eq_data = open('eq_data')
  lats, lons = [], []
  mag = []
  x,y = antmap(0,0)
  point = antmap.plot(x,y,'ro', markersize=5)[0]
  
  def init():
      point.set_data([],[])
      return point,
  
  # Begin Animation
  def animate(i):
      for i, line in enumerate(eq_data.readlines()):
          lats.append(float(line.split(',')[0]))
          lons.append(float(line.split(',')[1]))
          mag.append(float(line.split(',')[2]))
          x,y = antmap(lons, lats)
          point.set_data(x, y)
      return point,
  #    antmap.plot(x,y, 'ro', markersize=8)
  ani = animation.FuncAnimation(fig, animate, init_func=init, interval=500, blit=False)
  plt.show()
  </code></pre>
  
  <p>How would I animate these points?  I haven't been able to find anything else online thus far that has been able to animate these earthquake epicenters.  Thanks.  </p>
  
  <p><strong>UPDATED AND CORRECTED SCRIPT</strong></p>
  
  <pre><code>#!/usr/local/bin/python
  from mpl_toolkits.basemap import Basemap
  import matplotlib.pyplot as plt
  from matplotlib.animation import FuncAnimation
  import numpy as np
  
  # Create the Figure
  fig = plt.figure()
  
  
  #Build the basemap
  antmap = Basemap(projection='spstere', boundinglat=30, lon_0=-60, resolution='l')
  antmap.drawcoastlines(color='black', linewidth=0.15)
  #antmap.bluemarble()
  
  eq_data = open('eq_data')
  lats, lons = [], []
  mag = []
  x,y = antmap(lons,lats)
  
  for i, line in enumerate(eq_data.readlines()):
      lats.append(float(line.split(',')[0]))
      lons.append(float(line.split(',')[1]))
      mag.append(float(line.split(',')[2]))
  eq_data.close()
  
  antmap.plot(x,y,'ro', markersize=5)
  
  # Begin Animation
  def animate(i):
      x,y = antmap(lons[i], lats[i])
      antmap.plot(x,y,'ro', markersize=8)
  
  animation = FuncAnimation(fig, animate,  interval=100, blit=False)
  plt.show()
  </code></pre>