Data Plotting

Because liveserial supports simultaneous reading from multiple serial ports, each also supporting streams of data from multiple sensors, the plotting has to be flexible enough to support animation for multiple data sets. Plotting uses a single class that inherits from TimedAnimation and overrides the methods for frame drawing to get the latest data points from the LiveDataFeed. Using deque instances allows a fixed number of data points to be plotted so that the plot window moves intuitively as the stream continues to come in. Older values are discarded so that memory doesn’t become an issue either.

For unit testing, the base class initializer is ignored in favor of a standard system timer to test the drawing methods and the data acquisition and passing. The background is also switched to Agg so that no plot window is generated.

Methods for plotting the real-time data feed.

class liveserial.plotting.Plotter(livefeed, interval, maxlen=100, window=20, testmode=False, logger=None)[source]

Plots the live stream for each of the sensors in a subplot.

Parameters:
  • livefeed (monitor.LiveDataFeed) – data feed with the latest data points to plot. Also an attribute on the class instance.
  • interval (int) – how often (in milliseconds) to redraw the plot with the latest plot values.
  • maxlen (int) – maximum number of time points kept for each subplot.
  • window (float) – width of the plot window for sensors.
  • testmode (bool) – when True, the animator is not initialized so that a backend isn’t required to run the unit tests.
  • logger (log.Logger) – logger instance for interacting with config parameters.
lines

dict – of matplotlib.lines.Line2D being animated with the serial data; keyed by the sensor identifiers.

axes

dict – of matplotlib.axes.Axes being animated with the serial data; keyed by the sensor identifiers.

ts

dict – of lists of the last maxlen sensor timestamp readings.

ys

dict – of lists of the last maxlen sensor value readings. Keys for this dict are sensor names if only one value is specified in the sensor’s value_index config option; otherwise, the keys are (sensor, vindex) tuple, where vindex is the zero-based, integer column index being plotted.

stop()[source]

Cleans up the timer when the plotter is running in test mode.

liveserial.plotting.colorspace(size, cmap=<matplotlib.colors.LinearSegmentedColormap object>)[source]

Returns an cycler over a linear color space with ‘size’ entries.

Parameters:size (int) – the number of colors to define in the space.
Returns:iterable cycler with ‘size’ colors.
Return type:itertools.cycle