2011-08-17 5 views
1

私はリアルタイム信号をプロットしようとしています。私は新しいデータで1/32秒ごとにリフレッシュされるサイズ4の配列を持っており、これらの値を少なくとも1秒間プロットする必要があります。配列の変更をプロットする

つまり、それぞれサイズが4のアレイが32個あります。これは、サンプルの数(1,2,3 ... 128)に対してプロットするために32 * 4 = 128データ点を持つことを意味します。これをプロットする方法は?私は配列(サイズ4の)を新しいメソッドに戻すことができ、それは毎秒1/32秒ごとに行われるので、データが来るがそれを処理する方法はわからない。

私は私の質問を明確に説明しました。私はこの問題の助けに感謝します。

答えて

1

私はリアルタイムのもののためにwxPythonを使うのが好きです。ここでは、あなたが求めるものを行うアプリケーションの例を示します。生成された読み取り値とプロットをウィンドウで取得します。

(私はあなたのデータを見ることができないので、私は別のスレッドで正弦波を生成し、それをプロット)

import wx 
from Queue import Queue, Empty, Full 
import threading 
from time import sleep 
from math import sin 
from itertools import count 

class Producer(threading.Thread): 
    def __init__(self,queue): 
     self.queue=queue 
     self.t=0 
     threading.Thread.__init__(self) 
     self.daemon=False 


    def run(self): 
     print "initializing producer" 
     freq=0.1 
     secondsBetweenReadings=1.0/32 
     try: 
      while True: 
       readings=[ 256.0*sin(freq*t) for t in range(self.t,self.t+4) ] 
       self.t = self.t+4 
       self.queue.put(readings,timeout=0.1) 
       sleep(secondsBetweenReadings) 
     except Full: 
      print "Queue Full. Exiting" 

class App(wx.App): 
    def __init__(self,queue): 
     self.queue=queue 
     wx.App.__init__(self,redirect=False) 

    def OnInit(self): 
     self.frame=wx.Frame(parent=None,size=(256,256)) 
     self.plotPanel=wx.Panel(self.frame,size=(256,256)) 
     self.plotPanel.SetBackgroundColour(wx.BLACK) 
     self.data=[] 
     self.plotPanel.Bind(wx.EVT_PAINT,self.OnPaintPlot) 
     self.plotPanel.Bind(wx.EVT_ERASE_BACKGROUND,lambda evt: None) #For Windows 
     self.Bind(wx.EVT_IDLE,self.CheckForData) 
     self.frame.Show() 
     return True 

    def CheckForData(self,evt): 
     try: 
      data=self.queue.get(timeout=0.05) 
      self.data.extend(data) 
      self.plotPanel.Refresh() 
     except Empty: 
      pass 
     evt.RequestMore() 


    def OnPaintPlot(self,evt): 
     w,h=self.plotPanel.GetClientSize() 
     dc=wx.PaintDC(self.plotPanel) 
     dc.SetBrush(wx.BLACK_BRUSH) 
     dc.DrawRectangle(0,0,w,h) 
     dc.SetPen(wx.WHITE_PEN) 
     coords=zip(count(),self.data) 
     if len(coords) > 2: 
      dc.DrawLines(coords) 


if __name__ == "__main__": 
    maxReadings=32 
    queue=Queue(maxReadings) 
    producer=Producer(queue) 
    plotterApp=App(queue) 

    producer.start() 
    plotterApp.MainLoop() 
+0

はwxPythonのは、Python 2.5のために利用可能ですか? – dawnoflife

+0

はい。古いバージョンについては、[The sourceforge download page](http://sourceforge.net/projects/wxpython/files/wxPython/)をチェックしてください。 2.8.11はPython 2.5のバイナリを持っているようです – DanHorner

0

rtgraphパッケージをご覧ください。かなり柔軟性があり、これを処理できるはずです。

関連する問題