title: Matplotlib canvas drawing
body: <p>Let's say I define a few functions to do certain <code>matplotlib</code> actions, such as</p>
  
  <pre><code>def dostuff(ax):
      ax.scatter([0.],[0.])
  </code></pre>
  
  <p>Now if I launch <code>ipython</code>, I can load these functions and start a new figure:</p>
  
  <pre><code>In [1]: import matplotlib.pyplot as mpl
  
  In [2]: fig = mpl.figure()
  
  In [3]: ax = fig.add_subplot(1,1,1)
  
  In [4]: run functions # run the file with the above defined function
  </code></pre>
  
  <p>If I now call <code>dostuff</code>, then the figure does not refresh:</p>
  
  <pre><code>In [6]: dostuff(ax)
  </code></pre>
  
  <p>I have to then explicitly run:</p>
  
  <pre><code>In [7]: fig.canvas.draw()
  </code></pre>
  
  <p>To get the canvas to draw. Now I can modify dostuff to be</p>
  
  <pre><code>def dostuff(ax):
      ax.scatter([0.],[0.])
      ax.get_figure().canvas.draw()
  </code></pre>
  
  <p>This re-draws the canvas automatically. But now, say that I have the following code:</p>
  
  <pre><code>def dostuff1(ax):
      ax.scatter([0.],[0.])
      ax.get_figure().canvas.draw()
  
  def dostuff2(ax):
      ax.scatter([1.],[1.])
      ax.get_figure().canvas.draw()
  
  def doboth(ax):
      dostuff1(ax)
      dostuff2(ax)
      ax.get_figure().canvas.draw()
  </code></pre>
  
  <p>I can call each of these functions, and the canvas will be redrawn, but in the case of <code>doboth()</code>, it will get redrawn multiple times.</p>
  
  <p>My question is: how could I code this, such that the <code>canvas.draw()</code> only gets called once? In the above example it won't change much, but in more complex cases with tens of functions that can be called individually or grouped, the repeated drawing is much more obvious, and it would be nice to be able to avoid it. I thought of using decorators, but it doesn't look as though it would be simple.</p>
  
  <p>Any ideas?</p>