title: update an artiste (Line2D) on a figure without re-drawing the whole figure - axes.draw_artist() crashes
body: <p>I want a line (Line2D) object to move with the current cursor position on several axes of a figure. The way I'm doing it now is to re-draw the whole figure each time the cursor moves, by calling</p>
  
  <pre><code>fig.canvas.draw()
  </code></pre>
  
  <p>My figure consists in 14 panels among which 10 has a line which must move with the cursor, and doing this is very long.</p>
  
  <p>I was wondering how to update <strong>only</strong> the lines and not redrawing the whole thing.</p>
  
  <p>So I've tried to use</p>
  
  <pre><code>ax.draw_artist(line)
  </code></pre>
  
  <p>but this crashes. Here is a small example : </p>
  
  <pre><code>fig,ax =  subplots()
  line = Line2D([0.3,0.3],[0.1,0.8])
  ax.add_artist(line)
  fig.canvas.draw()
  
  #here I see the line on the figure ok
  
  # I update the position of the line
  line.set_xdata([0.6,0.8])
  
  # now draw the line (this should add another one (*))
  ax.draw_artist(line)
  </code></pre>
  
  <p>this last line causes the following error:</p>
  
  <blockquote>
    <p>--------------------------------------------------------------------------- RuntimeError                              Traceback (most recent call
    last)  in ()
    ----> 1 ax.draw_artist(line)</p>
    
    <p>/Users/Heimdall/anaconda/lib/python2.7/site-packages/matplotlib/axes.pyc
    in draw_artist(self, a)    2096         """    2097         assert
    self._cachedRenderer is not None
    -> 2098         a.draw(self._cachedRenderer)    2099    2100     def redraw_in_frame(self):</p>
    
    <p>/Users/Heimdall/anaconda/lib/python2.7/site-packages/matplotlib/artist.pyc
    in draw_wrapper(artist, renderer, *args, **kwargs)
         53     def draw_wrapper(artist, renderer, *args, **kwargs):
         54         before(artist, renderer)
    ---> 55         draw(artist, renderer, *args, **kwargs)
         56         after(artist, renderer)
         57</p>
    
    <p>/Users/Heimdall/anaconda/lib/python2.7/site-packages/matplotlib/lines.pyc
    in draw(self, renderer)
        524
        525         renderer.open_group('line2d', self.get_gid())
    --> 526         gc = renderer.new_gc()
        527         self._set_gc_clip(gc)
        528</p>
    
    <p>/Users/Heimdall/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.pyc
    in new_gc(self)
         95
         96     def new_gc(self):
    ---> 97         self.gc.save()
         98         self.gc.set_hatch(None)
         99         self.gc._alpha = 1.0</p>
    
    <p>RuntimeError: CGContextRef is NULL</p>
  </blockquote>
  
  <p>I'm not sure where this error comes from??</p>
  
  <p>Also, I've seen that I was supposed to somehow save the canvas before the first line is drawn and restore it each time I re draw it, so only one line appears. I've seen this could be done with :</p>
  
  <pre><code> background = canvas.copy_from_bbox(ax.bbox)
  </code></pre>
  
  <p>and restore it with</p>
  
  <pre><code>canvas.restore_region(background)
  </code></pre>
  
  <p>however I have neither of these two methods in the object 'canvas'. Is this a problem with the MacOSX backend?</p>
  
  <p>I have matplotlib 1.3.1 installed with the distribution anaconda on macOS 10.9.</p>
  
  <p>also I've been told I could use : </p>
  
  <pre><code>fig.canvas.blit(line.clipbox)
  </code></pre>
  
  <p>to draw the line at its new position, but that does absolutely nothing.</p>