我已经生成了matplotlib AxesSubplot对象的列表,我想将它们组合成一个图形,每个AxesSubplot对象都有一个子图。 让我们说我有9个AxesSubplot对象存储在名为" axlist"的python列表中。我想在3x3网格中一起显示它们:
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()
以下是我得到的: Figure with 3x3 subplots