Close pre-existing figures in matplotlib when running from eclipse

后端 未结 4 983
悲&欢浪女
悲&欢浪女 2021-02-04 23:27

My question is simple: I have a python script that generates figures using matplotlib. Every time i run it it generates new windows with figures. How can I have the script close

4条回答
  •  名媛妹妹
    2021-02-04 23:58

    You can close a figure by calling matplotlib.pyplot.close, for example:

    from numpy import *
    import matplotlib.pyplot as plt
    from scipy import *
    
    t = linspace(0, 0.1,1000)
    w = 60*2*pi
    
    
    fig = plt.figure()
    plt.plot(t,cos(w*t))
    plt.plot(t,cos(w*t-2*pi/3))
    plt.plot(t,cos(w*t-4*pi/3))
    plt.show()
    plt.close(fig)
    

    You can also close all open figures by calling matplotlib.pyplot.close("all")

提交回复
热议问题