6

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

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
F.grey
  • 87
  • 1
  • 2
  • 8
  • 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

1 Answers1

5

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,812
  • 8
  • 25
  • 29
  • 1
    +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