title: Return a subplot from a function
body: <p>Using Matplotlib in an IPython Notebook, I would like to create a figure with subplots which are returned from a function:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  %matplotlib inline
  
  def create_subplot(data):
      more_data = do_something_on_data()  
      bp = plt.boxplot(more_data)
      # return boxplot?
      return bp
  
  # make figure with subplots
  f, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(10,5))
  
  ax1 -&gt; how can I get the plot from create_subplot() and put it on ax1?
  ax1 -&gt; how can I get the plot from create_subplot() and put it on ax2?
  </code></pre>
  
  <p>I know that I can directly add a plot to an axis:</p>
  
  <pre><code>ax1.boxplot(data)
  </code></pre>
  
  <p>But how can I return a plot from a function and use it as a subplot?</p>