matplotlib: make plots in functions and then add each to a single subplot figure : <p>I haven't been able to find a solution to this.. Say I define some plotting function so that I don't have to copy-paste tons of code every time I make similar plots... </p>

<p>What I'd like to do is use this function to create a few different plots individually and then put them together as subplots into one figure. Is this even possible? I've tried the following but it just returns blanks:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

# function to make boxplots
def make_boxplots(box_data):

    fig, ax = plt.subplots()

    box = ax.boxplot(box_data)

    #plt.show()

    return ax

# make some data:
data_1 = np.random.normal(0,1,500)
data_2 = np.random.normal(0,1.1,500)

# plot it
box1 = make_boxplots(box_data=data_1)
box2 = make_boxplots(box_data=data_2)

plt.close('all')

fig, ax = plt.subplots(2)

ax[0] = box1
ax[1] = box2

plt.show()
</code></pre>
