title: How can one copy a matplotlib ax object
body: <p>Instead of the following: </p>
  
  <pre class="lang-py prettyprint-override"><code>fig, ax = plt.subplots()
  x = [1, 2]
  y = [4, 5]
  ax.scatter(x, y, s=100)
  </code></pre>
  
  <p>Which looks as 
  <a href="https://i.stack.imgur.com/SEzID.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SEzID.png" alt="enter image description here"></a></p>
  
  <p>I would like to have:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  def plot(ax, x, y):
      ax_c = copy.deepcopy(ax)
      ax_c.scatter(x, y, s=100)
      return ax_c
  
  
  
  fig, ax = plt.subplots()
  x = [1, 2]
  y = [4, 5]
  ax = plot(ax, x, y)
  </code></pre>
  
  <p>However, this doesn't work, with the following error:</p>
  
  <pre><code>NotImplementedError: TransformNode instances can not be copied. Consider using frozen() instead.
  </code></pre>
  
  <p>So, I'm wondering how I go about writing a function which takes a matplotlib <code>ax</code> as input, creates a copy of it, alters the copy, and returns it. The reason that I'd like to do so is so that I can have functions which are self-contained.</p>
  
  <h1>edit</h1>
  
  <p>the following is not a suitable solution: </p>
  
  <pre class="lang-py prettyprint-override"><code>def plot(ax_c, x, y):
      ax_c.scatter(x, y, s=100)
      return ax_c
  
  </code></pre>
  
  <p>because here the return statement could be replaced with <code>None</code> and it would still function fine. </p>