我目前正在尝试将多个图合并为一个图(带有子图)。请查看以下代码:
import matplotlib.pyplot as plt
a = list(range(1,10))
b = list(map(lambda x: x**2, a))
c = list(map(lambda x: x**3, a))
d = list(map(lambda x: x+200, a))
plots = []
plt.plot(a, b)
plots.append(plt.gcf())
plt.close()
plt.plot(a, c)
plots.append(plt.gcf())
plt.close()
plt.plot(b, c)
plots.append(plt.gcf())
plt.close()
plt.plot(a, d)
plots.append(plt.gcf())
plt.close()
fig, ax = plt.subplots(len(plots))
for i,plot_obj in enumerate(plots, start=1):
print(f"{i=}, {plot_obj=}")
ax[i].set_figure(plot_obj)
plot_obj.show()
plt.tight_layout()
plt.show()
# plt.savefig('temp.png')
Run Code Online (Sandbox Code Playgroud)
我的限制是 -
figure对象存储在列表中。RuntimeError: Can not put single artist in more than one …