Classes to plot data in the GUI.


Add all possible plot objects and options in list.


Plot objects need to be added to PLOT_LIST in order to be reachable.


Wrapper/decorator around an event that posts GUI events back to the main thread that our window is running in.

Parameters:fn (callable) – a function that does something to the GUI
class autopilot.core.plots.Plot_Widget[source]

Bases: PySide.QtGui.QWidget

Main plot widget that holds plots for all pilots

Essentially just a container to give plots a layout and handle any logic that should apply to all plots.

  • logger (logging.Logger) – The ‘main’ logger
  • plots (dict) – mapping from pilot name to Plot

For each pilot, instantiate a Plot and add to layout.

Parameters:pilot_list (list) – the keys from Terminal.pilots
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Plot(pilot, x_width=50)[source]

Bases: PySide.QtGui.QWidget

Widget that hosts a pyqtgraph.PlotWidget and manages graphical objects for one pilot depending on the task.


Key Method Description
‘START’ l_start() starting a new task
‘DATA’ l_data() getting a new datapoint
‘STOP’ l_stop() stop the task
‘PARAM’ l_param() change some parameter

Plot Parameters

The plot is built from the PLOT={data:plot_element} mappings described in the Task class. Additional parameters can be specified in the PLOT dictionary. Currently:

  • continuous (bool): whether the data should be plotted against the trial number (False or NA) or against time (True)
  • chance_bar (bool): Whether to draw a red horizontal line at chance level (default: 0.5)
  • chance_level (float): The position in the y-axis at which the chance_bar should be drawn
  • roll_window (int): The number of trials Roll_Mean take the average over.
  • pilot (str) –

    The name of our pilot, used to set the identity of our socket, specifically:

  • infobox (QtGui.QFormLayout) – Box to plot basic task information like trial number, etc.
  • info (dict) –

    Widgets in infobox:

    • ’N Trials’: QtGui.QLabel,
    • ’Runtime’ : Timer,
    • ’Session’ : QtGui.QLabel,
    • ’Protocol’: QtGui.QLabel,
    • ’Step’ : QtGui.QLabel
  • plot (pyqtgraph.PlotWidget) – The widget where we draw our plots
  • plot_params (dict) – A dictionary of plot parameters we receive from the Task class
  • data (dict) – A dictionary of the data we’ve received
  • plots (dict) – The collection of plots we instantiate based on plot_params
  • node (Net_Node) – Our local net node where we listen for data.
  • state (str) – state of the pilot, used to keep plot synchronized.
  • pilot (str) – The name of our pilot
  • x_width (int) – How many trials in the past should we plot?

Make pre-task GUI objects and set basic visual parameters of self.plot


Starting a task, initialize task-specific plot objects described in the Task.PLOT attribute.

Matches the data field name (keys of Task.PLOT ) to the plot object that represents it, eg, to make the standard nafc plot:

{'target'   : 'point',
 'response' : 'segment',
 'correct'  : 'rollmean'}
Parameters:value (dict) –

The same parameter dictionary sent by Terminal.toggle_start(), including

  • current_trial
  • step
  • session
  • step_name
  • task_type

Receive some data, if we were told to plot it, stash the data and update the assigned plot.

Parameters:value (dict) – Value field of a data message sent during a task.

Clean up the plot objects.

Parameters:value (dict) – if “graduation” is a key, don’t stop the timer.


Not implemented


Pilot letting us know its state has changed. Mostly for the case where we think we’re running but the pi doesn’t.

Parameters:value (Pilot.state) – the state of our pilot
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Point(color=(0, 0, 0), size=5, **kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

A simple point.

  • brush (QtGui.QBrush) –
  • pen (QtGui.QPen) –
  • color (tuple) – RGB color of points
  • size (int) – width in px.
Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is trial number and column 1 is the value, where value can be “L”, “C”, “R” or a float.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Segment(**kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

A line segment that draws from 0.5 to some endpoint.


data is doubled and then every other value is set to 0.5, then setData() is used with connect=’pairs’ to make line segments.

Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is trial number and column 1 is the value, where value can be “L”, “C”, “R” or a float.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Roll_Mean(winsize=10, **kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

Shaded area underneath a rolling average.

Typically used as a rolling mean of corrects, so area above and below 0.5 is drawn.

Parameters:winsize (int) – number of trials in the past to take a rolling mean of
Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is trial number and column 1 is the value.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Shaded(**kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

Shaded area for a continuous plot

Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is time and column 1 is the value.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Timer[source]

Bases: PySide.QtGui.QLabel

A simple timer that counts… time…

Uses a QtCore.QTimer connected to Timer.update_time() .

Parameters:update_interval (float) – How often (in ms) the timer should be updated.

you can read the sign ya punk


Called every (update_interval) milliseconds to set the text of the timer.

staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.HLine[source]

Bases: PySide.QtGui.QFrame

A Horizontal line.

staticMetaObject = <PySide.QtCore.QMetaObject object>
autopilot.core.plots.PLOT_LIST = {'point': <class 'autopilot.core.plots.Point'>, 'rollmean': <class 'autopilot.core.plots.Roll_Mean'>, 'segment': <class 'autopilot.core.plots.Segment'>, 'shaded': <class 'autopilot.core.plots.Shaded'>}

A dictionary connecting plot keys to objects.


Just reference the plot objects.