您好,我正在使用 matplotlib 中的子图在同一个图中绘制两个信号。我知道我不需要使用子图,可以只使用图,但对我来说它更容易理解。不管怎样,问题是我试图显示图形窗口,并且在执行脚本时,该窗口只出现第二次,足以让我看到它打开但立即关闭。 我尝试过 show(block = True) 和 show(blosk=False) 但出现错误。 这个实现怎么错了?我在下面一行中使用 savefig 会产生影响吗?
图形已正确保存,唯一未按预期工作的行是 show()。
def Ah_cha_and_dcha():
fig_Ah, ax1 = plt.subplots(nrows= 1, ncols = 1)
ax1.plot(time, Ah_Charge, label = 'Ah Charge')
ax1.plot(time, Ah_Disharge, label = 'Ah Discharge')
ax1.set_xlabel('Test Time [s]')
ax1.set_ylabel('Ah')
ax1.set_ylim(-1,110)
ax1.legend()
fig_Ah.savefig("Ah.png")
fig_Ah.show() # IT SHOWS FOR <1 SECOND!
使用 block=True 时
fig_Ah.show(block=True)
我收到错误 TypeError:Figure.show() 得到了意外的关键字参数“block”