title: How to update matplotlib pyplot on every iteration
body: <p>I am using rospy to get data of my robot's position and plot this in real time. </p>
  
  <p>This is what I have:</p>
  
  <pre><code> self.plot_pose()
  
   def plot_pose(self):
       plt.plot(self.pose[0], self.pose[1], 'o', color='green')
       plt.plot([self.pose[0], self.pose[0] - 0.5*np.cos(self.pose[2])],
                [self.pose[1], self.pose[1] + 0.5*np.sin(self.pose[2])],
                'k-', color='red', lw=2)
  
       plt.show(block=False)
       plt.pause(0.0001)
  </code></pre>
  
  <p>Unfortunately this doesn't erase the plot but overlays everything. So
  I tried using </p>
  
  <pre><code>plt.clf()
  plt.cla()
  </code></pre>
  
  <p>the first one gives me deprecation error and the second one gives me a blank plot for some reason. I am using python2.7 and rospy library.</p>
  
  <p>Any suggestions on how to update the plot would be greatly appreciated. </p>