Ich lief tatsächlich in dieses Problem (eher eine mentale Blockade, eigentlich ...).
Zuerst kopierte ich einige wx Plot-Code von wx Demo Code.
Was ich mache, ist ein Live-Log von einem Wert, und vergleichen Sie es mit zwei Marker (min und max, als rote und grüne gepunktete Linien angezeigt) (aber ich werde diese 2 Marker optional - daher die optionalen Parameter) .
Um das Live-Log zu implementieren, wollte ich zuerst die Deque-Klasse verwenden, aber da die Daten im Tupel-Modus (x, y-Koordinaten) sind, gab ich auf und versuchte die gesamte Parameterliste der Tupel neu zu schreiben: siehe _update_coordinates.
Es funktioniert gut für die Verfolgung der letzten 100-10.000 Grundstücke. Wäre auch ein printscreen enthalten, aber ich bin zu viel noob bei stackoverflow erlaubt :))
Mein Live-Parameter wird alle 0,25 Sekunden über einen 115kbps UART aktualisiert.
Der Trick ist am Ende, in der benutzerdefinierten Refresh-Methode!
ist hier die meiste Code:
class DefaultPlotFrame(wx.Frame):
def __init__(self, ymin=0, ymax=MAXIMUM_PLOTS, minThreshold=None,
maxThreshold=None, plotColour='blue',
title="Default Plot Frame",
position=(10,10),
backgroundColour="yellow", frameSize=(400,300)):
self.minThreshold = minThreshold
self.maxThreshold = maxThreshold
self.frame1 = wx.Frame(None, title="wx.lib.plot", id=-1, size=(410, 340), pos=position)
self.panel1 = wx.Panel(self.frame1)
self.panel1.SetBackgroundColour(backgroundColour)
self.ymin = ymin
self.ymax = ymax
self.title = title
self.plotColour = plotColour
self.lines = [None, None, None]
# mild difference between wxPython26 and wxPython28
if wx.VERSION[1] < 7:
self.plotter = plot.PlotCanvas(self.panel1, size=frameSize)
else:
self.plotter = plot.PlotCanvas(self.panel1)
self.plotter.SetInitialSize(size=frameSize)
# enable the zoom feature (drag a box around area of interest)
self.plotter.SetEnableZoom(False)
# list of (x,y) data point tuples
self.coordinates = []
for x_item in range(MAXIMUM_PLOTS):
self.coordinates.append((x_item, (ymin+ymax)/2))
self.queue = deque(self.coordinates)
if self.maxThreshold!=None:
self._update_max_threshold()
#endif
if self.lockThreshold!=None:
self._update_min_threshold()
#endif
self.line = plot.PolyLine(self.coordinates, colour=plotColour, width=1)
self.lines[0] = (self.line)
self.gc = plot.PlotGraphics(self.lines, title, 'Time', 'Value')
self.plotter.Draw(self.gc, xAxis=(0, MAXIMUM_PLOTS), yAxis=(ymin, ymax))
self.frame1.Show(True)
def _update_max_threshold(self):
if self.maxThreshold!=None:
self.maxCoordinates = []
for x_item in range(MAXIMUM_PLOTS):
self.maxCoordinates.append((x_item, self.maxThreshold))
#endfor
self.maxLine = plot.PolyLine(self.maxCoordinates, colour="green", width=1)
self.maxMarker = plot.PolyMarker(self.maxCoordinates, colour="green", marker='dot')
self.lines[1] = self.maxMarker
#endif
def _update_live_param(self, liveParam, minParam, maxParam):
if minParam!=None:
self.minThreshold = int(minParam)
self._update_min_threshold()
#endif
if maxParam!=None:
self.maxThreshold = int(maxParam)
self._update_max_threshold()
#endif
if liveParam!=None:
self._update_coordinates(int(liveParam))
#endif
def _update_coordinates(self, newValue):
newList = []
for x,y in self.coordinates[1:]:
newList.append((x-1, y))
#endfor
newList.append((x, newValue))
print "New list", newList
self.line = (plot.PolyLine(newList, colour=self.plotColour, width=1))
self.lines[0] = self.line
self.coordinates = newList
def _MyLIVE_MAGIC_refresh__(self, liveParam=None, minParam=None, maxParam=None):
self._update_live_param(liveParam, minParam, maxParam)
self.gc = plot.PlotGraphics(self.lines, self.title, 'Time', 'Value')
self.plotter.Draw(self.gc, xAxis=(0, MAXIMUM_PLOTS), yAxis=(self.ymin, self.ymax))
self.plotter.Refresh()
self.frame1.Refresh()
Ich habe von ähnlicher Sache zu denken; Löschen/Beschränken der Größe des Arrays. Sie haben Recht, abgesehen von Plot werden die Daten in einer Datei auf der Festplatte gespeichert. Trotzdem möchte ich, wenn möglich, ein Feature erstellen, in dem der Benutzer den gesamten/bestimmten Bereich des Plottings anzeigen kann (zusätzlich zum dynamischen Plotten, bei dem ich die X-Achsen-Grenze festlege). – teonghan