2011-08-17 3 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을 파이썬 2.5 사용할 수 있습니까? – dawnoflife

+0

예. 이전 버전의 경우 [The sourceforge download page] (http://sourceforge.net/projects/wxpython/files/wxPython/)를 확인하십시오. 2.8.11은 파이썬 2.5 용 바이너리를 갖고있는 것으로 보인다. – DanHorner

0

rtgraph 패키지를 확인하십시오. 꽤 유연하고 이것을 처리 할 수 ​​있어야합니다.