Odczytuję dane z gniazda w jednym wątku i chcę wydrukować i zaktualizować wykres w miarę nadejścia nowych danych. I kodowane małą prototyp do symulacji rzeczy, ale to nie działa:Czy umieścisz dane na żywo w matplotlib?
import pylab
import time
import threading
import random
data = []
# This just simulates reading from a socket.
def data_listener():
while True:
time.sleep(1)
data.append(random.random())
if __name__ == '__main__':
thread = threading.Thread(target=data_listener)
thread.daemon = True
thread.start()
pylab.figure()
while True:
time.sleep(1)
pylab.plot(data)
pylab.show() # This blocks :(
http://stackoverflow.com/questions/14665636/time-sleep-required-to-keep-qthread-responsive – tacaswell
http://stackoverflow.com/questions/8955869/why-is-plotting-with-matplotlib -so-slow/8956211 # 8956211 – tacaswell
http://stackoverflow.com/questions/11874767/real-time-plotting-in-while-loop-w-matplotlib/15724978#15724978 – tacaswell