2016-01-30 86 views
0

我有7個傳感器連接到一個微控制器,控制器使用串行端口發送數據到一臺電腦,我試圖用python實時繪製傳感器值的DrawNow功能,任何人可以幫助我在給予正確的語法一樣在同一圖在Python中使用drawnow繪製多個傳感器值

回答

0

繪出所有的傳感器怎麼樣了4個傳感器:

import time 
import matplotlib.pyplot as plt 
from drawnow import * 

sensors = 4 
x = dict([(s,[]) for s in range(0,sensors)]) # initialize dictionary of sensor stream values 

def makePlot(): 
    plt.subplot(411) 
    plt.plot(x[0],'r') 
    plt.subplot(412) 
    plt.plot(x[1],'g') 
    plt.subplot(413) 
    plt.plot(x[2],'b') 
    plt.subplot(414) 
    plt.plot(x[3],'c') 

for i in range(0,100): # simulate passage of time 
    time.sleep(1) # 1-sec delay for each loop 

    for s in range(0,sensors): 
     x[s].append(i*s) 

    drawnow(makePlot)