title: figure won't show in while loop
body: <p>as it will take a long time to deal with some data, I need to draw lines in a while loop after the data is okay. But figure can not show in the while loop, now I will paste a simplified code which can also mirror the same question. thank u for ur patience.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  x=np.linspace(0,2*pi,20)
  y=np.sin(x)
  z=np.cos(x)
  while 1:
      nPlt = input('input nPlt:')
      if nPlt == 1:
          plt.plot(x,y)
      elif nPlt == 2:
          plt.plot(x,z)
      else:
          break
  </code></pre>