live-plotter API Reference

class liveplotter.plotrecorder.PlotRecorder(port=5155)[source]

Bases: object

This is a ZMQ publisher

Parameters:port (int) – The port number to publish data (and subscribe to data)
close(var_name)[source]

Call this method for each variable name var_name to clean up the plotting process

Parameters:var_name – Name of variable to clean up.
record(var_name, var_value)[source]

Call this method each time you want to record a variable with name var_name and value var_value. Usually, there is one plot for each var_name.

Parameters:
  • var_name – Name of variable to record
  • var_value – Value of variable to record
class liveplotter.plotter.PlotterBase(var_name, port=5155, **init_kwargs)[source]

Bases: multiprocessing.context.Process

This is a ZMQ subscriber. To implement your own plotters, use this as your base class and implement functions plot_loop() and plot_once() as described in their respective documentation

See provided implementations below in liveplotter.plotter_impls

Parameters:
  • var_name – The name of the variable this class plots. This should match the variable name recorded by the class:.PlotRecorder class.
  • port (int) – The port number to subscribe to data
init()[source]

This method is called after a new process has been created, and should be used to initialize everything that needs to be initialized in the new process (i.e. after the fork). Override this method to create fig, ax etc. as needed

NOTE: This method SHOULD assign the created figure to the class variable self.fig.

loop(i)[source]

The function that runs the loop. At each call, it listens for a new message of the appropriate topic/var_name (given in the constructor). When it receives the message, it calls plot_loop()

Parameters:i (int) – The plot iteration passed in by the matplotlib animation api call
plot_loop(var_value, i)[source]

This method is called each time the plot needs to be updated. This should return an iterable of matplotlib matplotlib.artist.Artist

NOTE: This method should only use the local variables self.plt and self.fig etc. for plotting. Do not use global variables, since this can cause problems due to the multiprocessing being used (and matplotlib’s limited support for it)

Parameters:
Returns:

An iterable of matplotlib.artist.Artist

run()[source]

Entry point for the live plotting when started as a separate process. This starts the loop

class liveplotter.plotter_impls.GeneralPlotter(var_name, port=5155, **init_kwargs)[source]

Bases: liveplotter.plotter.PlotterBase

This does a live plot of a line of one (and only one) variable. Look at GeneralArrayPlotter if you want to plot multiple variables.

NOTE: None of its function should be called directly. These functions are indirectly called by PlotterBase and PlotRecorder

init(title=None, xlabel=None, ylabel=None, plot_frequency=10, **plot_kwargs)[source]

The init function that is called once at the beginning.

Parameters:
  • title – Plot title
  • xlabel – Plot xlabel
  • ylabel – Plot y label
  • plot_frequency – How often should the plot be updated? In the intermediate time steps the data is stored, but the plot itself is not updated
  • plot_kwargs – Any other arguments to be passed to the matplotlib plot function.
Returns:

self

plot_loop(data, it)[source]

The actual function that updates the data in the plot initialized in init()

Parameters:
  • data – The data that is recorded with PlotRecorder. It can be a just a scalar (in which case the iteration number is used on the x axis) OR a 2-D tuple with the first value containing the scalar to plot and the second value containing the corresponding x value.
  • it – The iteration number (independent of the actual x value)
Returns:

class liveplotter.plotter_impls.GeneralArrayPlotter(var_name, port=5155, **init_kwargs)[source]

Bases: liveplotter.plotter.PlotterBase

This does a live plot of lines for multiple variables variable. Look at GeneralPlotter if you want to plot only a single variable.

NOTE: None of its function should be called directly. These functions are indirectly called by PlotterBase and PlotRecorder

init(title=None, xlabel=None, ylabel=None, plot_frequency=10, **plot_kwargs)[source]

The init function that is called once at the beginning.

Parameters:
  • title – Plot title
  • xlabel – Plot xlabel
  • ylabel – Plot y label
  • plot_frequency – How often should the plot be updated? In the intermediate time steps the data is stored, but the plot itself is not updated
  • plot_kwargs – Any other arguments to be passed to the matplotlib plot function.
Returns:

self

plot_loop(data, it)[source]

The actual function that updates the data in the plot initialized in init()

Parameters:
  • data – The data that is recorded with PlotRecorder. It can be a just a vector with one value for every variable/line you want to plot (in which case the iteration number is used on the x axis) OR a 2-D tuple with the first value containing the vector to plot as above and the second value containing the corresponding x value.
  • it – The iteration number (independent of the actual x value)
Returns:

class liveplotter.plotter_impls.GeneralImagePlotter(var_name, port=5155, **init_kwargs)[source]

Bases: liveplotter.plotter.PlotterBase

This does a live plot of a 2-D image using matplotlib’s imshow

NOTE: None of its function should be called directly. These functions are indirectly called by PlotterBase and PlotRecorder

init(title=None, plot_frequency=10, **imshow_kwargs)[source]

The init function that is called once at the beginning.

Parameters:
  • title – Plot title
  • plot_frequency – How often should the plot be updated? In the intermediate time steps the data is dropped.
  • imshow_kwargs – Any other arguments to be passed to the matplotlib imshow function.
Returns:

self

plot_loop(image, it)[source]

The actual function that updates the data in the plot initialized in init()

Parameters:
  • image – The image that is recorded with PlotRecorder. It should be a 2-D numpy array
  • it – The iteration number (independent of the actual x value)
Returns:

class liveplotter.plotter_impls.SpikePlotter(var_name, port=5155, **init_kwargs)[source]

Bases: liveplotter.plotter.PlotterBase

This is specifically for plotting “spikes” i.e. binary arrays of 0s and 1s, where the index denotes the spike source

NOTE: None of its function should be called directly. These functions are indirectly called by PlotterBase and PlotRecorder

init(title=None, xlabel=None, ylabel=None, plot_frequency=10, **plot_kwargs)[source]

The init function that is called once at the beginning.

Parameters:
  • title – Plot title
  • xlabel – Plot xlabel
  • ylabel – Plot y label
  • plot_frequency – How often should the plot be updated? In the intermediate time steps the data is stored, but the plot itself is not updated
  • plot_kwargs – Any other arguments to be passed to the matplotlib plot function.
Returns:

self

plot_loop(data, it)[source]

The actual function that updates the data in the plot initialized in init()

Parameters:
  • data – The data that is recorded with PlotRecorder. It can be a just a vector with one binary value (0 or 1) for every spike source you want to plot (in which case the iteration number is used on the x axis) OR a 2-D tuple with the first value containing the vector of spikes to plot as above and the second value containing the corresponding x value.
  • it – The iteration number (independent of the actual x value)
Returns: