如何在 plt.show() 之后保持脚本运行

F.g*_*rey 7 python matplotlib

看完之后plt.show(),我只想继续。但需要关闭弹出图。我该怎么做才能跳过该操作?

这是我的代码:

plt.show()
time.sleep(1)
plt.close('all')
Run Code Online (Sandbox Code Playgroud)

其他代码

还有一个关于如何最大化数字制作的问题plt.show()

Mis*_*cic 5

我确实有类似的问题,并在这里找到了解决方案。我认为你需要 plt.ion()。一个例子

import numpy as np
from matplotlib import pyplot as plt

def main():
    plt.axis([-20,20,0,10000])
    plt.ion()
    plt.show()

    x = np.arange(-20, 21)
    for pow in range(1,5):   # plot x^1, x^2, ..., x^4
        y = [Xi**pow for Xi in x]
        plt.plot(x, y)
        plt.draw()
        plt.pause(0.001)
        input("Press [enter] to continue.")

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

工作正常,尽管它给出了这个警告

 MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented
  warnings.warn(str, mplDeprecation)
Run Code Online (Sandbox Code Playgroud)

我不确定这是否与 3.6 版本有关。