title: Realtime Subplots Execution Time
body: <p>The attached routine which I discussed recently in a related topic works well as intended.
  Unfortunately, when run on a fairly old computer, each while loop is taking quite some time to execute. A test to measure the duration of each loop starts with a figure of about 125ms and curiously increases slowly with each successive loop reaching to above 300ms. On a much more recent computer the numbers are better but still to high for my needs.</p>
  <p>Can anyone suggest ways of reducing execution times? Also, why does this number increase with each iteration?</p>
  <pre><code>import matplotlib.pyplot as plt
  import random
  import time
  
  x, y1, y2 =[],[],[]
  x_scale=30
  i=0
  
  fig, (ax1, ax2) = plt.subplots(2,sharex=True)
  fig.set_size_inches(8, 4)  # width and height in inches
  ax1.set_title(&quot;top chart&quot;)
  ax2.set_title(&quot;bottom chart&quot;)
  ax2.set_xlabel(&quot;TIME&quot;)
  ax1.set_ylabel(&quot;RND_1&quot;)
  ax2.set_ylabel(&quot;RND_2&quot;)
      
  
  while True:
  
      now =time.time()
      if len(x) &gt; x_scale:
          x.pop(0)
          y1.pop(0)
          y2.pop(0)
      x.append(i)
      ax1.set_xlim(i-x_scale, i)
      ax2.set_xlim(i-x_scale, i)
      ax1.set_ylim(0, 150)
      ax2.set_ylim(0, 20)
  
      y1.append(round(100*random.random()))
      y2.append(round(10*random.random()))
      ax1.plot(x,y1, color = 'b')
      ax2.plot(x,y2, color = 'r')
  
      plt.draw()
  #    plt.pause(0.01)
      if plt.waitforbuttonpress(0.01): break # this will wait 0.01 seconds for your keypress
      now1 = time.time()
      duration = round((now1-now)*1000)
      print(duration)
      i+=1
  </code></pre>