title: How do I change matplotlib's subplot projection of an existing axis?
body: <p>I'm trying to construct a simple function that takes a subplot instance (<code>matplotlib.axes._subplots.AxesSubplot</code>) and transforms its projection to another projection, for example, to one of the <code>cartopy.crs.CRS</code> projections.</p>
  
  <p>The idea looks something like this</p>
  
  <pre><code>import cartopy.crs as ccrs
  import matplotlib.pyplot as plt
  
  def make_ax_map(ax, projection=ccrs.PlateCarree()):
      # set ax projection to the specified projection
      ...
      # other fancy formatting
      ax2.coastlines()
      ...
  
  # Create a grid of plots
  fig, (ax1, ax2) = plt.subplots(ncols=2)
  # the first subplot remains unchanged
  ax1.plot(np.random.rand(10))
  # the second one gets another projection
  make_ax_map(ax2)
  </code></pre>
  
  <p>Of course, I can just use <code>fig.add_subplot()</code> function:</p>
  
  <pre><code>fig = plt.figure(figsize=(10,5))
  ax1 = fig.add_subplot(121)
  ax1.plot(np.random.rand(10))
  
  ax2 = fig.add_subplot(122,projection=ccrs.PlateCarree())
  ax2.coastlines()
  </code></pre>
  
  <p>but I was wondering if there is a proper <code>matplotlib</code> method to change a subplot axis projection <em>after</em> it was defined. Reading matplotlib API didn't help unfortunately.</p>