title: How can I prevent Python while loop from pausing each time the plot is generated until plot is closed?
body: <p>I am working on learning APIs and trying to do a live plot of weather data sampled every few minutes. I imagine the plot should be created outside of the while loop and then updated within the loop, but I cannot initialize it without any data. How can I make the plot persistent &amp; update with each loop without having to close the plot to continue to next loop?</p>
  <pre><code>plotdata = []
  
  while True:
      response = requests.get(f&quot;{url}q={q}&amp;units={units}&amp;appid={apikey}&quot;)
      obj = response.json()
      temp = obj[&quot;main&quot;][&quot;temp&quot;]
      text = json.dumps(obj, sort_keys=True, indent=4)
      now = datetime.now()
      current_time = now.strftime(&quot;%H:%M:%S&quot;)
      print(f&quot;Current temperature in Chicago at {current_time}: {temp}&quot;)
      plotdata.append((current_time, temp))
      plt.scatter(*zip(*plotdata))
      plt.show()
      time.sleep(2)
  </code></pre>