图绘制在先前的子图图上

Figure is plotted on previous subplot figure

我正在尝试使用 matplotlib 绘制一些子图,但出于某种原因,我在子图之后创建的图被打印在子图的最后一个图上。我以其中一个数字为例在下面发布了我的代码 As you can see, the last figure of the subplot has another figure plotted over it. This is supposed to be a separate figure

fig4 = plt.subplots(4)
plt.subplot(2, 3, 1)
plt.plot(T34, F34)
plt.plot(x_line342, y_line342, '--', color='red')
plt.title('test 1, 2nd order')

plt.subplot(2, 3, 2)
plt.plot(T34, F34)
plt.plot(x_line343, y_line343, '--', color='red')
plt.title('test 1, 3rd order')

plt.subplot(2, 3, 3)
plt.plot(T34, F34)
plt.plot(x_line344, y_line344, '--', color='red')
plt.title('test 1, 4th order')

plt.subplot(2, 3, 4)
plt.plot(T34, F34)
plt.plot(x_line345, y_line345, '--', color='red')
plt.title('test 1, 5th order')

plt.subplot(2, 3, 5)
plt.plot(T34, F34)
plt.plot(x_line346, y_line346, '--', color='red')
plt.title('test 1, 6th order')
plt.tight_layout()

plt.subplot(2, 3, 6)
plt.plot(T34, F34)
plt.plot(x_line346, y_line346, '--', color='red')
plt.title('test 1, 6th order')
plt.tight_layout()
plt.show

fig, axs = plt.subplots(2, 3)
axs[0, 0].plot(T34, F34)
axs[0, 0].plot(x_line342, y_line342, '--', color='red')
axs[0, 0].set_title('Axis [0, 0]')
axs[0, 1].plot(T34, F34)
axs[0, 1].plot(x_line343, y_line343, '--', color='red')
axs[0, 1].set_title('Axis [0, 1]')
axs[0, 2].plot(T34, F34)
axs[0, 2].plot(x_line344, y_line344, '--', color='red')
axs[0, 2].set_title('Axis [1, 0]')
axs[1, 0].plot(T34, F34)
axs[1, 0].plot(x_line345, y_line345, '--', color='red')
axs[1, 0].set_title('Axis [1, 1]')
axs[1, 1].plot(T34, F34)
axs[1, 1].plot(x_line346, y_line346, '--', color='red')
axs[1, 1].set_title('Axis [1, 1]')
axs[1, 2].plot(T34, F34)
axs[1, 2].plot(x_line346, y_line346, '--', color='red')
axs[1, 2].set_title('Axis [1, 1]')

for ax in axs.flat:
    ax.set(xlabel='x-label', ylabel='y-label')
for ax in axs.flat:
    ax.label_outer()

#%% plot best curves (4th order)
fig5=plt.plot(5)
plt.plot()
plt.plot(x_line314, y_line314, '--', color='red')
plt.plot(x_line324, y_line324, '--', color='red')
plt.plot(x_line334, y_line334, '--', color='red')
plt.plot(x_line344, y_line344, '--', color='red')
plt.show



print(y_line346)
fig6=plt.plot(6)
plt.plot()
plt.plot(x_line314, y_line314, '--', color='red')
plt.plot(x_line324, y_line324, '--', color='red')
plt.plot(x_line334, y_line334, '--', color='red')
plt.plot(x_line344, y_line344, '--', color='red')
plt.show

你应该全部改掉

plt.show

plt.show()

这可能会解决您的问题。