brainbox.plot_base

Functions

add_lines

Function to add vertical and horizontal reference lines to matplotlib axis

arrange_channels2banks

Rearranges data on channels so it matches geometry of probe.

plot_image

Function to create matplotlib plot from ImagePlot object

plot_line

Function to create matplotlib plot from LinePlot object

plot_probe

Function to create matplotlib plot from ProbePlot object

plot_scatter

Function to create matplotlib plot from ScatterPlot object.

scatter_xyc_plot

General function for preparing x y scatter plot with third variable encoded by colour of points

Classes

DefaultPlot

ImagePlot

LinePlot

ProbePlot

ScatterPlot

class DefaultPlot(plot_type, data)[source]

Bases: object

add_lines(pos, orientation, lim=None, style='--', width=3, color='k')[source]

Method to specify position and style of horizontal or vertical reference lines

Parameters:
  • pos – position of line

  • orientation – either ‘v’ for vertical line or ‘h’ for horizontal line

  • lim – extent of lines

  • style – line style

  • width – line width

  • color – line colour

Returns:

set_labels(title=None, xlabel=None, ylabel=None, zlabel=None, clabel=None)[source]

Set labels for plot

Parameters:
  • title – title

  • xlabel – x axis label

  • ylabel – y axis label

  • zlabel – z axis label

  • clabel – cbar label

Returns:

set_xlim(xlim=None)[source]

Set xlim values

Parameters:

xlim – xlim values (min, max) supports tuple, list or np.array of len(2). If not

specified will compute as min, max of y data

set_ylim(ylim=None)[source]

Set ylim values

Parameters:

ylim – ylim values (min, max) supports tuple, list or np.array of len(2). If not

specified will compute as min, max of y data

set_zlim(zlim=None)[source]

Set zlim values

Parameters:

zlim – zlim values (min, max) supports tuple, list or np.array of len(2). If not

specified will compute as min, max of z data

set_clim(clim=None)[source]

Set clim values

Parameters:

clim – clim values (min, max) supports tuple, list or np.array of len(2). If not

specified will compute as min, max of c data

convert2dict()[source]

Convert class object to dictionary

Returns:

dict with variables needed for plotting

class ImagePlot(img, x=None, y=None, cmap=None)[source]

Bases: DefaultPlot

set_scale(scale=None)[source]

Set the scaling factor to apply to image (mainly for pyqtgraph implementation)

Parameters:

scale – scale values (xscale, yscale), supports tuple, list or np.array of len(2).

If not specified will automatically compute from xlims/ylims and shape of data :return:

set_offset(offset=None)[source]

Set the offset to apply to the image (mainly for pyqtgraph implementation)

Parameters:

offset – offset values (xoffset, yoffset), supports tuple, list or np.array of len(2)

If not specified will automatically compute from minimum of xlim and ylim :return:

class ProbePlot(img, x, y, cmap=None)[source]

Bases: DefaultPlot

set_scale(idx=None, scale=None)[source]
set_offset(idx=None, offset=None)[source]
class ScatterPlot(x, y, z=None, c=None, cmap=None, plot_type='scatter')[source]

Bases: DefaultPlot

set_color(color=None)[source]

Color of scatter points.

Parameters:

color – string e.g ‘k’, single RGB e,g [0,0,0] or np.array of RGB. In the latter case

must give same no. of colours as datapoints i.e. len(np.array(RGB)) == len(data[‘x’]) :return:

set_marker_size(marker_size=None)[source]

Size of each scatter point

Parameters:

marker_size – int or np.array of int. In the latter case must give same no. of

marker_size as datapoints i.e len(np.array(marker_size)) == len(data[‘x’]) :return:

set_marker_type(marker_type=None)[source]

Shape of each scatter point

Parameters:

marker_type

Returns:

set_opacity(opacity=None)[source]

Opacity of each scatter point

Parameters:

opacity

Returns:

set_line_color(line_color=None)[source]

Colour of edge of scatter point

Parameters:

line_color – string e.g ‘k’ or RGB e.g [0,0,0]

Returns:

set_line_width(line_width=None)[source]

Width of line on edge of scatter point

Parameters:

line_width – int

Returns:

set_line_style(line_style=None)[source]

Style of line on edge of scatter point

Parameters:

line_style

Returns:

class LinePlot(x, y)[source]

Bases: ScatterPlot

add_lines(ax, data, **kwargs)[source]

Function to add vertical and horizontal reference lines to matplotlib axis

Parameters:
  • ax – matplotlib axis

  • data – dict of plot data

  • kwargs – matplotlib keywords arguments associated with vlines/hlines

Returns:

plot_image(data, ax=None, show_cbar=True, fig_kwargs={}, line_kwargs={}, img_kwargs={})[source]

Function to create matplotlib plot from ImagePlot object

Parameters:
  • data – ImagePlot object, either class or dict

  • ax – matplotlib axis to plot on, if None, will create figure

  • show_cbar – whether or not to display colour bar

  • fig_kwargs – dict of matplotlib keywords associcated with plt.subplots e.g can be

fig size, tight layout etc. :param line_kwargs: dict of matplotlib keywords associated with ax.hlines/ax.vlines :param img_kwargs: dict of matplotlib keywords associated with matplotlib.imshow :return: matplotlib axis and figure handles

plot_scatter(data, ax=None, show_cbar=True, fig_kwargs={}, line_kwargs={}, scat_kwargs=None)[source]

Function to create matplotlib plot from ScatterPlot object. If data[‘colors’] is given for each data point it will override automatic colours that would be generated from data[‘data’][‘c’]

Parameters:
  • data – ScatterPlot object, either class or dict

  • ax – matplotlib axis to plot on, if None, will create figure

  • show_cbar – whether or not to display colour bar

  • fig_kwargs – dict of matplotlib keywords associcated with plt.subplots e.g can be

fig size, tight layout etc. :param line_kwargs: dict of matplotlib keywords associated with ax.hlines/ax.vlines :param scat_kwargs: dict of matplotlib keywords associated with matplotlib.scatter :return: matplotlib axis and figure handles

plot_probe(data, ax=None, show_cbar=True, make_pretty=True, fig_kwargs={}, line_kwargs={})[source]

Function to create matplotlib plot from ProbePlot object

Parameters:
  • data – ProbePlot object, either class or dict

  • ax – matplotlib axis to plot on, if None, will create figure

  • show_cbar – whether or not to display colour bar

  • make_pretty – get rid of spines on axis

  • fig_kwargs – dict of matplotlib keywords associcated with plt.subplots e.g can be

fig size, tight layout etc. :param line_kwargs: dict of matplotlib keywords associated with ax.hlines/ax.vlines :return: matplotlib axis and figure handles

plot_line(data, ax=None, fig_kwargs={}, line_kwargs={})[source]

Function to create matplotlib plot from LinePlot object

Parameters:
  • data – LinePlot object either class or dict

  • ax – matplotlib axis to plot on

  • fig_kwargs – dict of matplotlib keywords associcated with plt.subplots e.g can be

fig size, tight layout etc. :param line_kwargs: dict of matplotlib keywords associated with ax.hlines/ax.vlines :return: matplotlib axis and figure handles

scatter_xyc_plot(x, y, c, cmap=None, clim=None, rgb=False)[source]

General function for preparing x y scatter plot with third variable encoded by colour of points

Parameters:
  • x

  • y

  • c

  • cmap

  • clim

  • rgb – Whether to compute rgb (set True when preparing pyqtgraph data)

Returns:

arrange_channels2banks(data, chn_coords, depth=None, pad=True, x_offset=1)[source]

Rearranges data on channels so it matches geometry of probe. e.g For Neuropixel 2.0 rearranges channels into 4 banks with checkerboard pattern

Parameters:
  • data – data on channels

  • chn_coords – local coordinates of channels on probe

  • depth – depth location of electrode (for example could be relative to bregma). If none

given will stay in probe local coordinates :param pad: for matplotlib implementation with NonUniformImage we need to surround our data with nans so that it shows as finite display :param x_offset: spacing between banks in x direction :return: list, data, x position and y position for each bank