python:如何保持脚本运行后plt.show()

问题描述:

plt.show()之后,我只想继续。但有必要关闭弹出式图形。我怎么能跳过这个动作?python:如何保持脚本运行后plt.show()

有我的代码:

plt.show() 
time.sleep(1) 
plt.close('all') 

其他代码

有关于如何通过plt.show()

+0

重复的[https://*.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue](https:/ /*.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue)。 –

+0

最大化该图:重复的[https://*.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python](https://*.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python) –

+0

@plinius_prem非常感谢你!你真是太好了。 –

我也有类似的问题,最大限度图制作等问题,并在这里找到解决方案SO.I认为你需要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() 

工作正常,虽然它给出了此警告

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

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