Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I actually ran into this problem (more of a mental block, actually...).</p> <p>First of all I copy-pasted some wx Plot code from <a href="http://wiki.wxpython.org/Using%20wxPython%20Demo%20Code" rel="nofollow">wx Demo Code</a>. </p> <p>What I do is keep a live log of a value, and compare it to two markers (min and max, shown as red and green dotted lines) (but I will make these 2 markers optional - hence the optional parameters).</p> <p>In order to implement the live log, I first wanted to use the deque class, but since the data is in tuple mode (x,y coordinates) I gave up and just tried to rewrite the entire parameter list of tuples: see _update_coordinates.</p> <p>It works just fine for keeping track of the last 100-10,000 plots. Would have also included a printscreen, but I'm too much of a noob at stackoverflow to be allowed :))</p> <p>My live parameter is updated every 0.25 seconds over a 115kbps UART.</p> <p>The trick is at the end, in the custom refresh method!</p> <p>Here is most of the code:</p> <pre><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] &lt; 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() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload