I have generated a list of matplotlib AxesSubplot object and I would like to combine them into one figure with a subplot for each AxesSubplot object. Let's say I have 9 AxesSubplot object stored in a python list called "axlist" and I want to display them together in a 3x3 grid:
def random_figure_generator(n):
"""
Create n random plots
"""
axlist = list()
for i in range(n):
fig, ax = plt.subplots()
x = sorted(np.random.random(100))
ax.plot(np.linspace(0,100,100), np.random.random(100))
plt.show(fig)
plt.close(fig)
axlist.append(ax)
return axlist
#Create a list of axes object
axlist = random_figure_generator(9)
#Attempt to combine them
axes = []
fig, axes = plt.subplots(3,3)
axes = axes.flatten()
for i in range(len(axlist)):
axes[i].axes = axlist[i] #try to assign each AxesSubplot object to one subplot in the new figure
plt.show()
And here is what I get: Figure with 3x3 subplots