python - real-time plotting in while loop with matplotlib -


i trying plot data camera in real time using opencv. real-time plotting (using matplotlib) doesn't seem working.

i've isolated problem simple example:

fig=plt.figure() plt.axis([0,1000,0,1])  i=0 x=list() y=list()  while <1000:     temp_y=np.random.random()     x.append(i)     y.append(temp_y)     plt.scatter(i,temp_y)     i+=1     plt.show() 

i expect example plot 1000 points individually. happens window pops first point showing (ok that), waits loop finish before populates rest of graph.

any thoughts why not seeing points populated 1 @ time?

here's working version of code in question (requires @ least version matplotlib 1.1.0 2011-11-14):

import numpy np import matplotlib.pyplot plt  plt.axis([0, 10, 0, 1]) plt.ion()  in range(10):     y = np.random.random()     plt.scatter(i, y)     plt.pause(0.05)  while true:     plt.pause(0.05) 

note of changes:

  1. call plt.ion() in order enable interactive plotting. plt.show(block=false) no longer available.
  2. call plt.pause(0.05) both draw new data , runs gui's event loop (allowing mouse interaction).

the while loop @ end keep window after data plotted.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -