假设一组 4 个 matplotlib 图形存储在变量 fig1 到 fig4 中。
import matplotlib.pyplot as plt
fig1 = plt.figure()
plt.plot([1, 2, 3, 4])
fig2 = plt.figure()
plt.plot([2, 2, 2, 2])
fig3 = plt.figure()
plt.plot([1, 3, 1, 4])
fig4 = plt.figure()
plt.plot([4, 3, 2, 1])
# code to create subplots using the fig1 to fig4 variables
# i.e. without recreating the original 4 plots
使用 matplotlib(或者可能是另一个包),如何创建子图图形(例如下面的示例),子图为 fig1 到 fig4?
最佳答案
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10,10))
#Set First Axis
ax1 = fig.add_subplot(121)
ax1.plot([1, 3, 1, 4])
#Set Second Axis
ax2 = fig.add_subplot(122)
ax2.plot([2, 2, 2, 2])
ax3 = fig.add_subplot(221)
ax3.plot([1, 3, 1, 4])
ax4 = fig.add_subplot(222)
ax4.plot([4, 3, 2, 1])
关于python - 如何使用变量中存储的图形作为子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55623612/