title: How to exit python matplotlib and continue code after that
body: <p>I have a problem with my python project. Right now I'm doing a real-time graph plotting using pyserial for Arduino and matplotlib. I want to plot temperature sensor data from Arduino into a graph in real-time. after I got the data, I want to proceed with other lines code after close the graph displayed. In this situation, I want to print 'ok' after I close the graph display. Here is the code that I use :</p>
  <pre><code>import serial
  import matplotlib.pyplot as plt
  import time
  
  
  plt.ion()
  fig=plt.figure()   
  i=0
  x1=list()
  y1=list()
  isrun = True
  ser = serial.Serial('COM3',9600)
  i=0
  ser.close()
  ser.open()
  run = True
  
  
  while True:
      data1 = ser.readline()
      print(data1.decode())
      x1.append(i)
      y1.append(data1.decode())
      plt.plot(x1, y1)
      plt.title('Temperature')
      i += 1
      plt.pause(0.005)
      plt.show(block=False)
      # if plt.close() :
      #     run= False
      #     ser.close()
      #     break
  
  print('ok')
  </code></pre>
  <p>In this case, I cannot print 'Ok' after close the real-time graph. It keeps on showing the graph even after I close it. It seems like they keep on doing the loop. I cannot find a way to break the loop and proceed with the next line code. How to break the loop for this case and proceed on the print 'ok'. Hope anyone can help..</p>