neurotools.graphics.plot module

Plotting helper routines

neurotools.graphics.plot.simpleaxis(ax=None)[source]

Only draw the bottom and left axis lines

Parameters:

ax (maplotlib.Axis; default plt.gca())

neurotools.graphics.plot.rightaxis(ax=None)[source]

Only draw the bottom and right axis lines. Move y axis to the right.

Parameters:

ax (maplotlib.Axis; default plt.gca())

neurotools.graphics.plot.simpleraxis(ax=None)[source]

Only draw the left y axis, nothing else

Parameters:

ax (maplotlib.Axis; default plt.gca())

neurotools.graphics.plot.simplerright(ax=None)[source]

Only draw the left y axis, nothing else

Parameters:

ax (maplotlib.Axis; default plt.gca())

neurotools.graphics.plot.noaxis(ax=None)[source]

Hide all axes

Parameters:

ax (maplotlib.Axis; default plt.gca())

neurotools.graphics.plot.nicey(**kwargs)[source]

Mark only the min/max value of y axis

Parameters:

**kwargs (dict) – Keyword arguments are forwarded to fudgey(**kwargs)

neurotools.graphics.plot.nicex(**kwargs)[source]

Mark only the min/max value of x axis

neurotools.graphics.plot.nicexy(xby=None, yby=None, **kwargs)[source]

Mark only the min/max value of y/y axis. See nicex and nicey

neurotools.graphics.plot.roundx(to=10)[source]

Round x axis limits to an integer multiple of to.

neurotools.graphics.plot.roundy(to=10)[source]

Round y axis limits to an integer multiple of to.

neurotools.graphics.plot.positivex()[source]

Sets the lower x limit to zero, and the upper limit to the largest positive value un the current xlimit. If the curent plt.xlim() is negative, a ValueError is raised.

neurotools.graphics.plot.positivey()[source]

Sets the lower y limit to zero, and the upper limit to the largest positive value un the current ylimit. If the curent plt.ylim() is negative, a ValueError is raised.

neurotools.graphics.plot.positivexy()[source]

Remove negative range from both x and y axes. See positivex and positivey

neurotools.graphics.plot.xylim(a, b, ax=None)[source]

set x and y axis limits to the same range

Parameters:
  • a (lower limit)

  • b (upper limit)

neurotools.graphics.plot.noclip(ax=None)[source]

Turn of clipping

neurotools.graphics.plot.notick(ax=None, axis='both', which='both')[source]

Hide axis ticks, but not their labels

neurotools.graphics.plot.nox()[source]

Hide x-axis

neurotools.graphics.plot.noy()[source]

Hide y-axis

neurotools.graphics.plot.noxyaxes()[source]

Hide all aspects of x and y axes. See nox, noy, and noaxis

neurotools.graphics.plot.noxlabels()[source]

Hide x tick labels and x axis label

neurotools.graphics.plot.noylabels()[source]

Hide y tick labels and y axis label

neurotools.graphics.plot.nolabels()[source]

Hide tick labels and axis labels

neurotools.graphics.plot.righty(ax=None)[source]

Move the y-axis to the right

neurotools.graphics.plot.unity(by=5, **kwargs)[source]

Set y-axis to unit interval

neurotools.graphics.plot.unitx()[source]

Set x-axis to unit interval

neurotools.graphics.plot.fsize(f=None)[source]
neurotools.graphics.plot.force_aspect(aspect=1, a=None)[source]
Parameters:
  • aspect (aspect ratio)

  • a (matplotlib.Axis, default None) – If None, uses gca()

neurotools.graphics.plot.square_compare(hi=1, lo=0, **kwargs)[source]

Force an axis to be square and draw a diagonal line for comparing equality of x and y values.

neurotools.graphics.plot.get_aspect(aspect=1, a=None)[source]
Parameters:

a (matplotlib.Axis, default None) – If None, uses gca()

Returns:

aspect

Return type:

aspect ratio of current axis

neurotools.graphics.plot.match_image_aspect(im, ax=None)[source]

Keep upper-left corner of axis fixed, but rescale width and height to match dimensions of the given image.

Parameters:
  • im (image instance to match)

  • ax (matplotlib.Axis, default None) – If None, uses gca()

neurotools.graphics.plot.unitaxes(a=None)[source]

Set both x and y axis to span [0,1]

Parameters:

a (matplotlib.Axis, default None) – If None, uses gca()

neurotools.graphics.plot.adjustmap(arraymap)[source]
Parameters:

arraymap (2D np.array)

Return type:

adjustmap

neurotools.graphics.plot.get_ax_size(ax=None, fig=None)[source]

Gets tha axis size in figure-relative units

Parameters:
  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Returns:

  • width (float)

  • height (float)

neurotools.graphics.plot.get_ax_pixel(ax=None, fig=None)[source]

Gets tha axis size in pixels

Parameters:
  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Returns:

  • width (float)

  • height (float)

neurotools.graphics.plot.get_ax_pixel_ratio(ax=None, fig=None)[source]

Gets tha axis aspect ratio from pixel size

Parameters:
  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Returns:

aspect_ratio

Return type:

float

neurotools.graphics.plot.pixels_to_xunits(n, ax=None, fig=None)[source]

Converts a measurement in pixels to units of the current x-axis scale

Parameters:
  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.yunits_to_pixels(n, ax=None, fig=None)[source]

Converts a measurement in units of the current y-axis to pixels

Parameters:
  • n (number) – y position in pixels

  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.xunits_to_pixels(n, ax=None, fig=None)[source]

Converts a measurement in units of the current x-axis to pixels

Parameters:
  • n (number) – x position in pixes

  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.pixels_to_yunits(n, ax=None, fig=None)[source]

Converts a measurement in pixels to units of the current y-axis scale.

Parameters:
  • n (number) – number of pixels

  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.pixels_to_xfigureunits(n, fig=None)[source]

Converts a measurement in pixels to units of the current figure width scale.

Parameters:
  • n (number) – x coordinate in pixels.

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.px2x(n, ax=None, fig=None)

Converts a measurement in pixels to units of the current x-axis scale

Parameters:
  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.px2y(n, ax=None, fig=None)

Converts a measurement in pixels to units of the current y-axis scale.

Parameters:
  • n (number) – number of pixels

  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.pixels_to_yfigureunits(n, fig=None)[source]

Converts a measurement in pixels to units of the current figure height scale.

Parameters:
  • n (number) – y coordinate in pixels.

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.xfigureunits_to_pixels(n, ax=None, fig=None)[source]

Converts a measurement in figure-width units to units of x-axis pixels

Parameters:
  • n (number) – x coordinate in figure-width units

  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.yfigureunits_to_pixels(n, ax=None, fig=None)[source]

Converts a measurement in figure-height units to units of y-axis pixels

Parameters:
  • n (number) – y coordinate in figure units

  • ax (matplotlib.Axis, default None) – If None, uses gca()

  • fig (matplotlib.Figure, default None) – If None, uses gcf()

Return type:

float

neurotools.graphics.plot.adjust_ylabel_space(n, ax=None)[source]
Parameters:
  • n (float) – Desired value for ax.yaxis.labelpad

  • ax (axis, default None) – If None, uses gca()

neurotools.graphics.plot.adjust_xlabel_space(n, ax=None)[source]
Parameters:
  • n (float) – Desired value for ax.xaxis.labelpad

  • ax (axis, default None) – If None, uses gca()

neurotools.graphics.plot.get_bbox(ax=None)[source]

Get bounding box of currenta axis

Parameters:

ax (axis, default None) – If None, uses gca()

Returns:

  • x (float)

  • y (float)

  • w (float)

  • h (float)

neurotools.graphics.plot.nudge_axis_y_pixels(dy, ax=None, fig=None)[source]

Moves axis dx pixels. Direction of dx may depend on axis orientation. Does not change axis height.

Parameters:
  • dy (number) – Amount (in pixels) to adjust by

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.adjust_axis_height_pixels(dy, ax=None, fig=None)[source]

resize axis by dy pixels. Direction of dx may depends on axis orientation. Does not change the baseline position of axis.

Parameters:
  • dy (number) – Amount (in pixels) to adjust by

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.nudge_axis_y(dy, ax=None, fig=None)[source]

This does not change the height of the axis

Parameters:
  • dy (number) – Amount (in pixels) to adjust by

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.nudge_axis_up(dy, ax=None)[source]
neurotools.graphics.plot.nudge_axis_down(dy, ax=None)[source]
neurotools.graphics.plot.nudge_axis_x(dx, ax=None, fig=None)[source]

This does not change the width of the axis.

Parameters:
  • dx (number) – Amount (in pixels) to adjust axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.expand_axis_x(dx, ax=None, fig=None)[source]

Expands the width of the x axis

Parameters:
  • dx (number) – Amount (in pixels) to adjust x axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.expand_axis_y(dy, ax=None, fig=None)[source]

Adjusts the axis height, keeping the lower y-limit the same.

Parameters:
  • dy (number) – Amount (in pixels) to adjust axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.nudge_axis_baseline(dy, ax=None, fig=None)[source]

Moves bottom limit of axis, keeping top limit the same. This will change the height of the y axis.

Parameters:
  • dy (number) – Amount (in pixels) to adjust axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.nudge_axis_top(dy, ax=None, fig=None)[source]

Moves top limit of axis, keeping bottom limit the same. This will change the height of the y axis.

Parameters:
  • dy (number) – Amount (in pixels) to adjust axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.nudge_axis_left(dx, ax=None, fig=None)[source]

Moves the left x-axis limit, keeping the right limit intact. This changes the width of the plot.

Parameters:
  • dx (number) – Amount (in pixels) to adjust axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.nudge_axis_right(dx, ax=None, fig=None)[source]

Moves the right x-axis limit, keeping the left limit intact. This changes the width of the plot.

Parameters:
  • dx (number) – Amount (in pixels) to adjust axis

  • ax (axis, default None) – If None, uses gca()

  • fig (figure, default NOne) – If None, uses gcf()

neurotools.graphics.plot.expand_axis_outward(dx, dy=None)[source]

Expand all edges of axis outward by dx pixels.

neurotools.graphics.plot.fudgex(by=None, ax=None, doshow=False)[source]

Adjust x label spacing in pixels

Parameters:
  • by (number of pixels)

  • axis (axis object to change; defaults to current axis)

  • dishow (boolean; if true, calls plt.show())

neurotools.graphics.plot.fudgey(by=None, ax=None, doshow=False)[source]

Adjust y label spacing in pixels

Parameters:
  • by (number of pixels)

  • axis (axis object to change; defaults to current axis)

  • dishow (boolean; if true, calls plt.show())

neurotools.graphics.plot.fudgexy(by=10, ax=None)[source]

Adjust x and y label spacing in pixels

Parameters:
  • by (number of pixels)

  • axis (axis object to change; defaults to current axis)

  • dishow (boolean; if true, calls plt.show())

neurotools.graphics.plot.vtwin(ax1, ax2)[source]

Assuming that ax2 is directly below ax1, move ax2 up to directly abut the base of ax1. (Used for making horizontal paired-histogram plots).

Parameters:
  • ax1 (axis 1)

  • ax2 (axis 2)

neurotools.graphics.plot.zoombox(ax1, ax2, xspan1=None, xspan2=None, draw_left=True, draw_right=True, lw=1, color='k')[source]

Draw lines on figure connecting two axes, to indicate that one is a “zoomed in” version of the other.

The axes should be placed atop one another with the “zoomed in” axis below for this to work.

Parameters:
  • ax1 (axis) – Axis to zoom in to

  • ax2 (axis) – Axis reflecting zoomed-in portion

  • xspan1 (tuple; default None) – (x_start, x_stop) span to connect on the first axis.

  • xspan2 (tuple; default None) – (x_start, x_stop) span to connect on the second axis.

  • draw_left (boolean; default True)

  • draw_right (boolean; default True)

  • lw (number; default 1)

  • color (matplotlib color; default 'k')

neurotools.graphics.plot.shade_edges(edges, color=(0.5, 0.5, 0.5, 0.5), **kwargs)[source]

Edges of the form (start,stop) Shades regions of graph defined by “edges”

Parameters:
  • edges

  • color

neurotools.graphics.plot.ybartext(x, t, c1='k', c2='w', outline=False, fontsize=12, **kwargs)[source]

Draws an axvline() spanning the current y-axis limits (plt.ylim()), with an appropriately spaced (and optionally outlined) label at the top left.

Parameters:
  • y (number) – Y position

  • t (str)

  • c1 (matplotlib color; default 'k') – Text color.

  • c2 (matplotlib color; default 'w') – Color of text outline, if outline=True.

  • outline (boolean; default False) – Whether to outline the text.

  • **kwargs (dict) – keyword arguments forwarded to plot() and text().

neurotools.graphics.plot.xbartext(y, t, c1='k', c2='w', outline=False, fontsize=12, **kwargs)[source]

Draws an axhline() spanning the current x-axis limits (plt.xlim()), with an appropriately spacedd (and optionally outlined) label at the top left.

Parameters:
  • x (number) – X position

  • t (str)

  • c1 (matplotlib color; default 'k') – Text color.

  • c2 (matplotlib color; default 'w') – Color of text outline, if outline=True.

  • outline (boolean; default False) – Whether to outline the text.

  • **kwargs (dict) – keyword arguments forwarded to plot() and text().

neurotools.graphics.plot.nice_legend(*args, **kwargs)[source]

Better defaults for the plot legend.

Parameters:
  • *args (arguments forwarded to legend())

  • **kwargs (keyword arguments forwarded to legend())

neurotools.graphics.plot.right_legend(*args, fudge=0.0, **kwargs)[source]

Legend outside the plot to the right.

Parameters:
  • *args (arguments forwarded to legend())

  • **kwargs (keyword arguments forwarded to legend())

neurotools.graphics.plot.left_legend(*args, **kwargs)[source]

Legend outside the plot to the left.

Parameters:
  • *args (arguments forwarded to legend())

  • **kwargs (keyword arguments forwarded to legend())

neurotools.graphics.plot.base_legend(*args, fudge=-0.1, **kwargs)[source]

Legend outside the plot on the base.

Parameters:

fudge (padding between legend and axis, default -0.1)

neurotools.graphics.plot.top_legend(*args, fudge=0.1, **kwargs)[source]

Legend outside the plot on the top.

Parameters:

fudge (padding between legend and axis, default -0.1)

neurotools.graphics.plot.rangeto(rangefun, data)[source]
Parameters:
  • rangefun

  • data

neurotools.graphics.plot.rangeover(data)[source]

data: np.array

: tuple

np.min(data),np.max(data)

neurotools.graphics.plot.cleartop(x)[source]
Parameters:

x

neurotools.graphics.plot.plotCWT(ff, cwt, aspect='auto', vmin=None, vmax=None, cm='afmhot', interpolation='nearest', dodraw=1)[source]

Plotting helper for continuous wavelet transform.

Parameters:
  • ff (numeric) – frequencies

  • cwt (numeric) – wavelet transformed data (what orientation?)

neurotools.graphics.plot.plotWTPhase(ff, cwt, aspect=None, ip='nearest')[source]

Plot the phase of a wavelet transform

neurotools.graphics.plot.wtpshow(ff, cwt, aspect=None, ip='nearest')

Plot the phase of a wavelet transform

neurotools.graphics.plot.plotWTPhaseFig(ff, cwt, aspect=50, vmin=None, vmax=None, cm='bone', interpolation='nearest')[source]

Plot the phase of a wavelet transform

neurotools.graphics.plot.domask(*args)[source]
class neurotools.graphics.plot.HandlerSquare(patch_func=None, **kwargs)[source]

Bases: HandlerPatch

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[source]
neurotools.graphics.plot.plot_complex(z, vm=None, aspect='auto', ip='bicubic', extent=None, onlyphase=False, previous=None, origin='lower')[source]

Renders complex np.array as image, in polar form with magnitude mapped to lightness and hue mapped to phase.

Parameters:
  • z – 2D np.array of complex values

  • vm – max complex modulus. Default of None will use max(np.abs(z))

  • aspect – image aspect ratio. defaults auto

  • ip – interpolation mode to forward to imshow. defaults bicubic

  • extent – extents (dimensions) for imshow. defaults None.

  • previous – if available, output of a previous call to plot_complex can be used to skirt replotting nuisances and update data directly, which should be a little faster.

Return img:

a copy of the result of imshow, which can be reused in subsequent calls to speed things up, if animating a video

neurotools.graphics.plot.animate_complex(z, vm=None, aspect='auto', ip='bicubic', extent=None, onlyphase=False, previous=None, origin='lower')[source]

Like plot_complex except has an additional dimension for time

neurotools.graphics.plot.good_colorbar(vmin=None, vmax=None, cmap=None, image=None, title='', ax=None, sideways=False, border=True, spacing=5, width=15, labelpad=10, fontsize=10, labelsize=None, scale=1.0, va='c', ha='c')[source]

Matplotlib’s colorbar function is pretty bad. This is less bad. r’$mathrm{mu V}^2$’

Parameters:
  • vmin (number) – min value for colormap

  • vmax (number) – mac value for colormap

  • cmap (colormap) – what colormap to use

  • title (string) – Units for colormap

  • ax (axis) – optional, defaults to plt.gca(). axis to which to add colorbar

  • sideways (bool) – Flips the axis label sideways

  • border (bool) – Draw border around colormap box?

  • spacing (number) – distance from axis in pixels. defaults to 5

  • width (number) – width of colorbar in pixels. defaults to 15

  • labelpad (number) – padding between colorbar and title in pixels, defaults to 10

  • fontsize (number) – title font size, defaults to 10

  • labelsize (number) – tick label font size, defaults to fontsize

  • scale (float) – height adjustment relative to parent axis, defaults to 1.0

  • va (str) – vertical alignment; “bottom” (‘b’), “center” (‘c’), or “top” (‘t’)

  • ha (str) – horizontal alignment; “left” (‘l’), “center” (‘c’), or “right” (‘r’)

Returns:

colorbar axis

Return type:

axis

neurotools.graphics.plot.complex_axis(scale)[source]

Draws a nice complex-plane axis with LaTeX Re, Im labels.

Parameters:

scale (float)

neurotools.graphics.plot.subfigurelabel(x, fontsize=10, dx=39, dy=7, ax=None, bold=True, **kwargs)[source]
Parameters:

x (label)

neurotools.graphics.plot.sigbar(x1, x2, y, pvalue=None, dy=5, padding=1, fontsize=10, color=array([0.26666668, 0.32156864, 0.36078432], dtype=float32), label_pvalue=True, **kwargs)[source]

Draw a significance bar between positions x1 and x2 at height y.

Parameters:
  • x1 (float) – X position of left of brace

  • x2 (float) – X position of right of brace

  • y (float) – Y position to start brace

  • dy (float; default 5) – Brace height in pixels

  • padding (float; default 1) – Padding between brace and label, in pixels

  • fontsize (float; default 10) – Label font size

  • color (matplotlib.color; default BLACK) – Brace color

  • label_pvalue (boolean; default True) – Label p-value in scientific notation

  • **kwargs – Forwarded to the plot() command that draws the brace.

neurotools.graphics.plot.hsigbar(y1, y2, x, pvalue=None, dx=5, padding=1, fontsize=10, color=array([0.26666668, 0.32156864, 0.36078432], dtype=float32), label_pvalue=True, **kwargs)[source]

Draw a significance bar between position y1 and y2 at horizontal position x.

Parameters:
  • y1 (float)

  • y2 (float)

  • x (float)

  • dx (float; default 5) – Brace width in pixels

  • padding (float; default 1) – Padding between brace and label, in pixels

  • fontsize (float; default 10) – Label font size

  • color (matplotlib.color; default BLACK) – Brace color

  • label_pvalue (boolean; default True) – Label p-value in scientific notation

  • **kwargs – Forwarded to the plot() command that draws the brace.

neurotools.graphics.plot.savefigure(name, stamp=True, **kwargs)[source]

Saves figure as both SVG and PDF, prepending the current date-ti,me in YYYYMMDD_HHMMSS format

Parameters:

name (string) – file name to save as (sans extension)

neurotools.graphics.plot.clean_y_range(ax=None, precision=1)[source]

Round down to a specified number of significant figures

Parameters:
  • ax (axis)

  • precision (int)

neurotools.graphics.plot.round_to_precision(x, precision=1)[source]

Round to a specified number of significant figures

Parameters:
  • x (scalar) – Number to round

  • precision (positive integer, default=1) – Number of digits to keep

Returns:

x – Rounded number

Return type:

scalar

neurotools.graphics.plot.ceil_to_precision(x, precision=1)[source]

Round up to a specified number of significant figures

Parameters:
  • x (scalar) – Number to round

  • precision (positive integer, default=1) – Number of digits to keep

Returns:

  • x (scalar) – Rounded number

  • ——-

neurotools.graphics.plot.floor_to_precision(x, precision=1)[source]

Round down to a specified number of significant figures

Parameters:
  • x (scalar) – Number to round

  • precision (positive integer, default=1) – Number of digits to keep

Returns:

x – Rounded number

Return type:

scalar

neurotools.graphics.plot.expand_y_range(yvalues, ax=None, precision=1, pad=1.2)[source]
Parameters:

yvalues

neurotools.graphics.plot.Gaussian2D_covellipse(M, C, N=60, **kwargs)[source]

xy = Gaussian2D_covellipse(M,C,N=60,**kwargs)

Plot a covariance ellipse for 2D Gaussian with mean M and covariance C Ellipse is drawn at 1 standard deviation

Parameters:
  • M (tuple of (x,y) coordinates for the mean)

  • C (2x2 np.array-like covariance matrix)

  • N (optional, number of points in ellipse (default 60))

Returns:

xy

Return type:

list of points in the ellipse

neurotools.graphics.plot.stderrplot(m, v, color='k', alpha=0.1, smooth=None, lw=1.5, filled=True, label=None, stdwidth=1.96)[source]

Plot mean±1.96*σ

Parameters:
  • m (mean)

  • v (variance)

  • color – Plot color

  • alpha – Shaded confidence alpha color blending value

  • smooth (int) – Number of samples over which to smooth the variance

neurotools.graphics.plot.yscalebar(ycenter, yheight, label, x=None, color='k', fontsize=9, ax=None, side='left', pad=2)[source]

Add vertical scale bar to plot

Parameters:
  • ycenter

  • yheight

  • label

  • x (number default None)

  • color (default 'k')

  • fontsize (default 9)

  • ax (default None)

  • side (default 'left')

  • pad (default 2)

neurotools.graphics.plot.xscalebar(xcenter, xlength, label, y=None, color='k', fontsize=9, ax=None)[source]

Add horizontal scale bar to plot

Parameters:
  • xcenter (float) – Horizontal center of the scale bar

  • xlength (float) – How wide the scale bar is

neurotools.graphics.plot.addspikes(Y, lw=0.2, color='k')[source]

Add vertical lines where Y>0

neurotools.graphics.plot.unit_crosshairs(draw_ellipse=True, draw_cross=True)[source]
neurotools.graphics.plot.covariance_crosshairs(S, p=0.8, draw_ellipse=True, draw_cross=True)[source]

For 2D Gaussians these are the confidence intervals p | sigma 90 : 4.605 95 : 5.991 97.5: 7.378 99 : 9.210 99.5: 10.597

Parameters:
  • S (2D covariance matrix)

  • p (fraction of data ellipse should enclose)

neurotools.graphics.plot.draw_circle(radius, centX, centY, angle_, theta2_, arrowsize=1, ax=None, cap_start=1, cap_end=1, **kwargs)[source]
Parameters:

ax (axis, if None (default), uses the current axis.)

neurotools.graphics.plot.simple_arrow(x1, y1, x2, y2, ax=None, s=5, color='k', lw=1.5, **kwargs)[source]

Connect two points with a triangular error.

Parameters:
  • x1 (float)

  • y1 (float)

  • x2 (float)

  • y2 (float)

  • ax (axis, if None (default), uses the current axis.)

  • s (float; passed as the headlength and headwidth arrow property.)

  • width (float; line width)

  • color (matplotlib color)

neurotools.graphics.plot.inhibition_arrow(x1, y1, x2, y2, ax=None, width=0.5, color='k')[source]

Connect two points with a T (inhibition; braking) arrow.

Parameters:
  • x1 (float)

  • y1 (float)

  • x2 (float)

  • y2 (float)

  • ax (axis; if None (default), uses the current axis.)

  • width (float; line width)

  • color (matplotlib color)

neurotools.graphics.plot.figurebox(color=(0.6, 0.6, 0.6))[source]

Draw a colored border around the edge of a figure.

Parameters:

color (matplotlib.color, default (.6,)*3)

neurotools.graphics.plot.more_xticks(ax=None)[source]

Add more ticks to the x axis

Parameters:

ax (axis, if None (default), uses the current axis.)

neurotools.graphics.plot.more_yticks(ax=None)[source]

Add more ticks to the y axis

Parameters:

ax (axis, if None (default), uses the current axis.)

neurotools.graphics.plot.border_width(lw=0.4, ax=None)[source]

Adjust width of axis border

Parameters:
  • lw (line width of axis borders to use)

  • ax (axis, if None (default), uses the current axis.)

neurotools.graphics.plot.broken_step(x, y, eps=1e-05, *args, **kwargs)[source]

Draws a step plot but does not connect adjacent levels with vertical lines

Parameters:
  • x (horizontal position of steps)

  • y (height of steps)

  • eps (step size above which to break; default is 1e-5)

  • **args (arguments forwarded to plot())

  • **kwargs (keyword arguments forwarded to plot())

neurotools.graphics.plot.label(x='', y='', t='')[source]

Convenience function for setting x label, y label, and title in one command.

Parameters:
  • x (string, optional; x-axis label)

  • y (string, optional; y-axis label)

  • t (string, optional; title)

neurotools.graphics.plot.flathist(x)[source]
neurotools.graphics.plot.barcompare(x, y, bins=20, mode='p50', markersize=7, lw=1.5, **kwargs)[source]

Bar plot of Y as a function of X, summarized in bins of X

neurotools.graphics.plot.shellmean(x, y, bins=20)[source]

Get mean and standard deviation of Y based on histogram bins of X μ, σ, dμ, Δe = shellmean(x,y,bins=20)

neurotools.graphics.plot.trendline(x, y, ax=None, color=array([0.92156863, 0.47843137, 0.34901962], dtype=float32))[source]

Plot a trend line

Parameters:
  • x – x points

  • y – y points

  • ax – figure axis for plotting, if None uses plt.gca()

neurotools.graphics.plot.shellplot(x, y, z, SHELLS, label='', vmin=None, vmax=None, ax=None)[source]

Averages X and Y based on bins of Z

Parameters:
  • x

  • y

  • z

  • SHELLS

neurotools.graphics.plot.arrow_between(A, B, size=None)[source]

Draw an arrow between two matplotlib axis instances

Parameters:
  • A (matplotlib.Axis)

  • B (matplotlib.Axis)

  • size (positive float; default None)

neurotools.graphics.plot.splitz(z, thr=1e-09)[source]

Split a 1D complex signal into real and imaginary parts, setting components that are zero in either to np.NaN. This lets us plot components separately without overlap (see plotz()).

Parameters:
  • z

  • thr (positive float; default 1e-9)

neurotools.graphics.plot.plotz(x, z, thr=1e-09, **k)[source]

Plot a 1D complex signal, drawing the imaginary component as a dashed line.

Parameters:
  • x

  • z

  • thr (positive float; default 1e-9)

neurotools.graphics.plot.save_limits()[source]

Stash the current ((x0,x1),(y0,y1) axis limits in __SAVE_LIMITS_PRIVATE_STORAGE__. These can be restored later via restore_limits()

neurotools.graphics.plot.restore_limits()[source]

Restore the ((x0,x1),(y0,y1) limits stored in __SAVE_LIMITS_PRIVATE_STORAGE__

neurotools.graphics.plot.mock_legend(names, colors=None, s=40, lw=0.6, marker='s', styles=None)[source]

For a list of (labels, colors), generate some square scatter points outside the axis limits with the given labels, so that the legend() call will populate a list of labelled, colored squares.

This does not actually draw the legend, but rather mock-up some off-screen labelled scatter points that can be used to populate the legend.

Use pyplot.legend() or one of the neurotools.graphics.plot helpers nice_legend() right_legend() base_legend() to draw the legend after calling this function.

Parameters:
  • labels (list of str) – List of labels to create

  • colors (list of matplotlib.color) –

    List of label colors, same length as labels

    If a single color is given, I will use this for all markers. However, there is an edge case if specifying a RGB tuple as a list with len(names)==3. This will cause an error.

  • s (int; default 40) – Size of markers. Can also be a list of sizes.

  • ls (float; default 0.6) – Line width for markers. Can also be a list of line width.

  • marker (str; default 's' (square)) – Matplotlib marker character. Can also be a list of Matplotlib marker characters.

  • styles (list of dictionaries) – To pass as keword arguments for each marker. Overrides ALL other options.

neurotools.graphics.plot.xtickpad(pad=0, ax=None, which='both')[source]

Adjust padding of xticks to axis

Parameters:
  • pad (positive float; default 0) – Distance between axis and ticks

  • ax (matplotlib.axis or None; default None) – If None, uses pyplot.gca()

  • which (str in {'major','minor','both'}; default 'both') – Which set of ticks to apply to

neurotools.graphics.plot.ytickpad(pad=0, ax=None, which='both')[source]

Adjust padding of yticks to axis

Parameters:
  • pad (positive float; default 0) – Distance between axis and ticks

  • ax (matplotlib.axis or None; default None) – If None, uses pyplot.gca()

  • which (str in {'major','minor','both'}; default 'both') – Which set of ticks to apply to

neurotools.graphics.plot.xticklen(l=0, w=None, ax=None, which='both', **kwargs)[source]

Set length and width of x ticks.

Parameters:
  • l (positive float; default 0) – Length of ticks

  • w (positive float; default 0) – Width of ticks

  • ax (matplotlib.axis or None; default None) – If None, uses pyplot.gca()

  • which (str in {'major','minor','both'}; default 'both') – Which set of ticks to apply to

neurotools.graphics.plot.yticklen(l=0, w=None, ax=None, which='both', **kwargs)[source]

Set length and width of y ticks.

Parameters:
  • l (positive float; default 0) – Length of ticks

  • w (positive float; default 0) – Width of ticks

  • ax (matplotlib.axis or None; default None) – If None, uses pyplot.gca()

  • which (str in {'major','minor','both'}; default 'both') – Which set of ticks to apply to

neurotools.graphics.plot.xin(ax=None, which='both')[source]

Make x ticks point inward

Parameters:
  • ax (matplotlib.axis or None; default None) – If None, uses pyplot.gca()

  • which (str in {'major','minor','both'}; default 'both') – Which set of ticks to apply to

neurotools.graphics.plot.yin(ax=None, which='both')[source]

Make y ticks point inward

Parameters:
  • ax (matplotlib.axis or None; default None) – If None, uses pyplot.gca()

  • which (str in {'major','minor','both'}; default 'both') – Which set of ticks to apply to

neurotools.graphics.plot.lighten(color, amount)[source]

Lighten matplotlib color by amount (0=do nothing). Alpha channel is discarded

Parameters:
  • color (matplotlib.color) – Color to lighten

  • amount (float in [0,1]) – Amount to lighten by. 0: do nothing, 1: make white.

Returns:

Lightened color

Return type:

rgb

neurotools.graphics.plot.darken(color, amount)[source]

Lighten matplotlib color by amount (0=do nothing). Alpha channel is discarded

Parameters:
  • color (matplotlib.color) – Color to lighten

  • amount (float in [0,1]) – Amount to lighten by. 0: do nothing, 1: make white.

Returns:

Lightened color

Return type:

rgb

neurotools.graphics.plot.axvstripe(edges, colors, fade=0.0, **kwargs)[source]

Shade vertical spans of edges in alternating bands.

Parameters:
  • edges (list of numbers) – x coordinates of edges of shaded bands

  • colors (color or list of colors) – If a single color, will alternated colored/white. If a list of colors, will rotate within list

  • alpha (positive float ∈[0,1]; default 0) – Amount of white to mix into the colors

neurotools.graphics.plot.axvbands(widths, colors=array([0.26666668, 0.32156864, 0.36078432], dtype=float32), fade=0.8, startat=0, **kwargs)[source]

Wrapper for axvstripe that accepts band widths rather than edges.

Parameters:
  • widths (list of numbers) – Width of each band

  • colors (color or list of colors) – If a single color, will alternated colored/white. If a list of colors, will rotate within list

  • alpha (positive float ∈[0,1]; default 0) – Amount of white to mix into the colors

  • startat (number, default 0) – Starting position of bands

neurotools.graphics.plot.zerohline(color='k', lw=None, **kwargs)[source]

Draw horizontal line at zero matching axis style.

Parameters:
  • color (matplotlib.color; default 'k')

  • lw (positive float) – Linewidth, if different from axes.linewidth

neurotools.graphics.plot.zerovline(color='k', lw=None, **kwargs)[source]

Draw vertical line at zero matching axis style.

Parameters:
  • color (matplotlib.color; default 'k')

  • lw (positive float) – Linewidth, if different from axes.linewidth

neurotools.graphics.plot.plot_circular_histogram(x, bins, r, scale, color=array([0.26666668, 0.32156864, 0.36078432], dtype=float32), alpha=0.8)[source]

Plot a circular histogram for data x, given in degrees.

Parameters:
  • x (np.array) – Values to plot, in degrees

  • bins (positive int) – Number of anugular bins to use

  • r (positive float) – Radius of hisogram

  • scale (positive float) – Scale of histogram

  • color (matplotlib.color; default BLACK)

  • alpha (float in [0,1]; default 0.8)

neurotools.graphics.plot.plot_quadrant(xlabel='←$\\mathrm{noise}$→', ylabel='←$\\varnothing$→')[source]
Parameters:
  • xlabel (str; default '←$mathrm{noise}$→',)

  • ylabel (str; default '←$varnothing$→')

neurotools.graphics.plot.quadrant_axes(q=0.2)[source]
neurotools.graphics.plot.nicebp(bp, color='k', linewidth=0.5)[source]

Improve the appearance of a box and whiskers plot. To be called on the object returned by the matplotlib boxplot function, with accompanying color information.

Parameters:
  • bp (point to boxplot object returned by matplotlib)

  • c (matplotlib.color; default 'k') – Color to set boxes to

  • linewidth (positive float; default 0.5) – Width of whisker lines.

neurotools.graphics.plot.colored_violin(data, position=1, color=array([0.92156863, 0.47843137, 0.34901962], dtype=float32), edgecolor=array([0.94509804, 0.9411765, 0.9137255], dtype=float32), width=0.75, lw=0.8)[source]
neurotools.graphics.plot.colored_boxplot(data, positions, color, filled=True, notch=False, showfliers=False, lw=1, whis=[5, 95], bgcolor=array([0.94509804, 0.9411765, 0.9137255], dtype=float32), mediancolor=None, **kwargs)[source]

Boxplot with nicely colored default style parameters

Parameters:
  • data (NPOINTS × NGROUPS np.float32) – Data sets to plot

  • positions (NGROUPS iterable of numbers) – X positions of each data group

  • color (matplotlib.color) – Color of boxplot

  • filled (boolean; default True) – Whether to fill boxes with color

  • notch (boolean; default False) – Whether to inset a median notch

  • showfliers (boolean; default False) – Whether to show outlies as scatter points

  • lw (positive float; default 1.) – Width of whisker lines

  • which (tuple; default (5,95)) – Percentile range for whiskers

  • bgcolor (matplotlib.color; default WHITE) – Background color if filled=False

  • mediancolor (matplotlib.color; default None) – Defaults to BLACK unless color is BLACK, in which case it defaults to WHITE.

  • **kwargs – Additional arguments fowarded to pyplot.boxplot()

neurotools.graphics.plot.boxplot_significance(a1, positionsa, b1=None, positionsb=None, fdr=0.05, dy=5, fontsize=6, label_pvalue=True, significance_mark='∗', paired=True)[source]

Perform Wilcoxon tests on a pair of box-plot sets and add significance brackets.

Note that this, by default, assumed paired samples. Please set paired=False.

This corrects for multiple comparisons using the Benjamini-Hochberg procedure, using either the variance for positive dependence or no dependence, whichever is more conservative.

Parameters:
  • a1 (NGROUPS×NPOINTS np.float32) – Condition A

  • positionsa (NGROUPS iterable of numbers) – X positions of each of group A

  • b1 (NGROUPS×NPOINTS np.float32; Default None) – Condition B

  • positionsb (NGROUPS iterable of numbers; Default None) – X positions of each of group B

  • fdr (float in (0,1); default 0.05) – Desired false discovery rate for Benjamini Hochberg correction

  • dy (positive number; default 5) – Padding, in pixels, between box and p-value annotation

  • fontsize (postiive float; default 6) – Font size of p-value, if shown

  • label_pvalue (boolean; default True) – Only for single-population tests. Whether to draw corrected p-value for significant boxes.

  • significance_mark (str; default '∗') – Only for single-population tests. Marker to use to note significant boxes.

  • paired (boolean; default True) – Whether to compare conditions using paired or unpaired tests.

Returns:

  • pvalues (np.float32) – List of corrected pvalues for each box or comparison between a pair of boxes

  • is_significant (np.bool) – List of booleans indicating whether given box or pair of boxes was signfiicant at the specified falst discovery rate threshold after correcting for multiple comparisons.

neurotools.graphics.plot.simplestem(x, y, **kwargs)[source]

Plot timeseries as verical lines dropped to y=0. Keyword arguments are forwarded to pyplot.plot().

Obsolete: use matplotlib.pyplot.stem instead

Parameters:
  • x (1D np.array) – X Location of bars

  • y (1D np.array) – Y position of bars

neurotools.graphics.plot.pike(x, y, bins=10, bin_mode='percentile', point_function='mean', error_mode='pct', error_range=[2.5, 97.5], dolines=True, dopoints=True, doscatter=True, connect_points=False, doplot=True, color=None, linestyle={}, pointstyle={}, scatterstyle={}, bin_offset=0.0, w=None, label=None, nbootstrap=500, sideways=False)[source]

Summarize data mean or median within bins.

Parameters:
  • x (iterable) – x coordinates of data

  • y (iterable) – y coordinates of data

  • bins (positive int; default 10)

  • bin_mode (str; default 'percentile') – 'percentile': bins based on data percentiles’ 'uniform': evenly spaced bins between min and max.

  • point_function (str; default 'mean') – 'mean' or 'median'

  • error_mode (str; default 'p') – 'e' Standard error of mean; 's' Standard deviation of data; 'p' Percentiles of data; 'b' Bootstrap error of mean or median.

  • error_range (tuple of numbers ∈(0,100); default (2.5,97.5)) – Lower and upper percentiles to use for error bars.

  • dolines (boolean; default True) – Whether to draw error lines.

  • dopoints (boolean; default True) – Whether to draw mean/median points.

  • doscatter (boolean; default True) – Wheter to plot (x,y) as scatter points.

  • connect_points (boolean; default False) – Whether to connect the points in a line plot.

  • doplot (boolean; default True) – Whether to draw a plot

  • linestyle (dict) – Keyword arguments for line style

  • pointstyle (dict) – Keyword arguments for mean/median style

  • scatterstyle (dict) – Keyword arguments for scatter points style

  • bin_offset (float) – Fraction of median inter-bin distance to offset the error lins. This adjustment allows plotting of multiple series atop each-other without overlap.

  • nbootstrap (int; default 200) – Number of bootstrap samples

  • sideways (boolean, default False) – Flips the role of the x and y axes

Returns:

  • xc (list) – x bin centers

  • points (list) – mean or median of y in each bin

  • lo (list) – lower data or error percentile in each bin

  • hi (list) – upper data or error percentile in each bin

neurotools.graphics.plot.confidencebox(x, y, median=None, boxcolor=array([0.92156863, 0.47843137, 0.34901962], dtype=float32), w=0.5, **kwargs)[source]

Use a box plot to draw a 2.5–97.5% confidence interval, taking care of some tegious arguments.

Parameters:
  • x (number) – x location of box

  • y (iterable) – samples from which to draw the box

  • median (number) – central value whose confidence interval this box plot represents

  • boxcolor (matplotlib.color; default RUST) – Box’s color

  • **kwargs (dictionary) – Overrides for any boxplot arguments. See pyplot.boxplot() for more details.

neurotools.graphics.plot.anatomy_axis(x0, y0, dx=15, dy=None, tx=4, ty=None, l='M', r='L', u='A', d='P', fontsize=8)[source]

Draw an anatomical axis crosshairs on the current axis.

Parameters:
  • x0 (number) – X coordinate of anatomy axis.

  • y0 (number) – Y coordinate of anatomy axis.

  • dx (positive number; default 15) – Width of axis in pixels

  • dy (positive number; default dx) – Height of axis in pixels

  • tx (positive number; default 4) – Horizontal label padding in pixels

  • ty (positive number; default tx) – Vertical label padding in pixels

  • l (str; default 'M') – Label for leftwards direction

  • r (str; default 'L') – Label for rightwards direction

  • u (str; default 'A') – Label for upwards direction

  • d (str; default 'P') – Label for downwards direction

  • fontsize (positive number; 8) – Font size for labels

neurotools.graphics.plot.vpaired_histogram(ax1, ax2, x1, x2, bins=10, color1='teal', color2='orange', name1='', name2='', label='← (density) →', labelpad=20, labelproperties={})[source]

Draw a veritically paired histogram.

>>> vpaired_histogram(subplot(211), subplot(212), randn(100), randn(100))
Parameters:
  • ax1 (axis) – The top axis

  • ax2 (axis) – The bottom axis. This will be shifted to abut the top axis and match its width.

  • x1 (iterable of numbers) – Data for top histogram

  • x2 (iterable of numbers) – Data for bottom histogram

  • bins (int or series; default 10) – Histogram bin edges or number of histogram bins.

  • color1 (matplotlib color) – Color of top histogram

  • color2 (matplotlib color) – Color of bottom histogram

  • name1 (str) – Label for top histogram

  • name2 (str) – Label for bottom histogram

  • label (str) – Y axis label

  • labelpad (int) – Y axis label spacing in pixels

  • labelproperties (dict) – Keyword arguments forwarded to figure.text() for drawing the Y axis label.

neurotools.graphics.plot.hollow_polygon(outer, inner, **kwargs)[source]

Add a polygon with a single interior region subtracted to the current plot.

neurotools.graphics.plot.add_polygon(points, **kwargs)[source]

Add a closed polygon to the current plot.

neurotools.graphics.plot.linscale_polar_plot(h, r, rinner, router, lw=0.8, facecolor=array([0.81666666, 0.8303921, 0.8401961], dtype=float32), edgecolor=array([0.6333333, 0.6607843, 0.68039215], dtype=float32), alpha=1.0, ntheta=360, zorder=-500, flipud=False, clip_on=False)[source]
neurotools.graphics.plot.vonmises_ring(kappa, loc, rinner, router, lw=0.8, facecolor=array([0.81666666, 0.8303921, 0.8401961], dtype=float32), edgecolor=array([0.6333333, 0.6607843, 0.68039215], dtype=float32), color=None, alpha=1.0, ntheta=360, draw_mean=True, markerprops={}, zorder=-500, flipud=False, clip_on=False)[source]

Plot a von Mises distribution in polar coordinates, with inverse-dispersion parameter kappa, location parameter loc (mean angle in radians), baseline at rinner, and peak at router.

neurotools.graphics.plot.disk_axis(r1, r2, nspokes=12, facecolor=array([0.87725484, 0.8792157, 0.8584314], dtype=float32), edgecolor=array([0.33450982, 0.3835294, 0.41607842], dtype=float32), lw=0.4, zorder=-100, fix_limits=True, clip_on=False, draw_inner=True, draw_outer=True)[source]

Disk axis: Draw a disk with alternating white/colored sectors like a roulette wheel.

Parameters:
  • r1 (positive float) – Radius of lower axis limit, r1>0.

  • r2 (positive float) – Radius of upper axis limit, r2>r1.

  • nspokes (non-negative integer) – Number of bands/spokes to draw, default is 12.

  • facecolor (matplotlib color) – Color of bands/spokes; Default is OFFWHITE defined in neurotools.graphics.color.

  • edgecolor (matplotlib color) – Color of the upper/lower radius axes; Default is OFFBLACK defined in neurotools.graphics.color.

  • lw (positive float, default 0.4)

  • zorder (numeric, default -100)

  • fix_limits (boolean, default True)

  • clip_on (boolean, default False)

  • draw_inner (boolean, default True)

  • draw_outer (boolean, default True)