4

After the plt.show() , I just want to continue. However it is necessary to close the Pop-up Figure. how could i do to skip the action ?

there is my codes:

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

other codes

there is other question about how to maximize the figure making by plt.show()

F.grey
  • 67
  • 1
  • 2
  • 8
  • duplicate of [https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue](https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue). – dummman Aug 30 '17 at 08:41
  • maximizing the figure: duplicate of [https://stackoverflow.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python](https://stackoverflow.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python) – dummman Aug 30 '17 at 08:43
  • @plinius_prem thank you very much ! you are so gerat. – F.grey Aug 30 '17 at 08:51
  • @plinius_prem thanks for your help. there is other question about how to save the maximized figure by `plt.savefig` – F.grey Aug 30 '17 at 09:08

1 Answers1

3

I did have a similar problem and found solution here on SO.I think that you need plt.ion().One example

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()

Works fine,although it gives this warning

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

I am not sure if that is related to 3.6 version or not.

MishaVacic
  • 1,686
  • 6
  • 22
  • 28
  • +1 Out of several SO answers, this is the one that works for me. NB I had to add `plt.pause(0.1)` after the initial `plt.show()` to display the first figure. Other answers suggested `draw` alone, `pause` alone, `ion` alone, using `show(block=False)`... none of these worked. – Petr Vepřek Mar 26 '20 at 15:12