sporco.plot

Plotting/visualisation functions

Functions

plot(y[, x, ptyp, xlbl, ylbl, title, lgnd, lglc])

Plot points or lines in 2D.

surf(z[, x, y, elev, azim, xlbl, ylbl, ...])

Plot a 2D surface in 3D.

contour(z[, x, y, v, xlog, ylog, xlbl, ...])

Contour plot of a 2D surface.

imview(img[, title, copy, fltscl, intrp, ...])

Display an image.

close([fig])

Close figure(s).

set_ipython_plot_backend([backend])

Set matplotlib backend within an ipython shell.

set_notebook_plot_backend([backend])

Set matplotlib backend within a Jupyter Notebook shell.

config_notebook_plotting()

Configure plotting functions for inline plotting within a Jupyter Notebook shell.


Function Descriptions

sporco.plot.plot(y, x=None, ptyp='plot', xlbl=None, ylbl=None, title=None, lgnd=None, lglc=None, **kwargs)[source]

Plot points or lines in 2D. If a figure object is specified then the plot is drawn in that figure, and fig.show() is not called. The figure is closed on key entry ‘q’.

Parameters
yarray_like

1d or 2d array of data to plot. If a 2d array, each column is plotted as a separate curve.

xarray_like, optional (default None)

Values for x-axis of the plot

ptypstring, optional (default ‘plot’)

Plot type specification (options are ‘plot’, ‘semilogx’, ‘semilogy’, and ‘loglog’)

xlblstring, optional (default None)

Label for x-axis

ylblstring, optional (default None)

Label for y-axis

titlestring, optional (default None)

Figure title

lgndlist of strings, optional (default None)

List of legend string

lglcstring, optional (default None)

Legend location string

**kwargsmatplotlib.lines.Line2D properties or figure properties, optional

Keyword arguments specifying matplotlib.lines.Line2D properties, e.g. lw=2.0 sets a line width of 2, or properties of the figure and axes. If not specified, the defaults for line width (lw) and marker size (ms) are 1.5 and 6.0 respectively. The valid figure and axes keyword arguments are listed below:

kwarg

Accepts

Description

fgsz

tuple (width,height)

Specify figure dimensions in inches

fgnm

integer

Figure number of figure

fig

matplotlib.figure.Figure object

Draw in specified figure instead of creating one

ax

matplotlib.axes.Axes object

Plot in specified axes instead of current axes of figure

Returns
figmatplotlib.figure.Figure object

Figure object for this figure

axmatplotlib.axes.Axes object

Axes object for this plot

sporco.plot.surf(z, x=None, y=None, elev=None, azim=None, xlbl=None, ylbl=None, zlbl=None, title=None, lblpad=8.0, alpha=1.0, cntr=None, cmap=None, fgsz=None, fgnm=None, fig=None, ax=None)[source]

Plot a 2D surface in 3D. If a figure object is specified then the surface is drawn in that figure, and fig.show() is not called. The figure is closed on key entry ‘q’.

Parameters
zarray_like

2d array of data to plot

xarray_like, optional (default None)

Values for x-axis of the plot

yarray_like, optional (default None)

Values for y-axis of the plot

elevfloat

Elevation angle (in degrees) in the z plane

azimfoat

Azimuth angle (in degrees) in the x,y plane

xlblstring, optional (default None)

Label for x-axis

ylblstring, optional (default None)

Label for y-axis

zlblstring, optional (default None)

Label for z-axis

titlestring, optional (default None)

Figure title

lblpadfloat, optional (default 8.0)

Label padding

alphafloat between 0.0 and 1.0, optional (default 1.0)

Transparency

cntrint or sequence of ints, optional (default None)

If not None, plot contours of the surface on the lower end of the z-axis. An int specifies the number of contours to plot, and a sequence specifies the specific contour levels to plot.

cmapmatplotlib.colors.Colormap object, optional (default None)

Colour map for surface. If none specifed, defaults to cm.YlOrRd

fgsztuple (width,height), optional (default None)

Specify figure dimensions in inches

fgnminteger, optional (default None)

Figure number of figure

figmatplotlib.figure.Figure object, optional (default None)

Draw in specified figure instead of creating one

axmatplotlib.axes.Axes object, optional (default None)

Plot in specified axes instead of creating one

Returns
figmatplotlib.figure.Figure object

Figure object for this figure

axmatplotlib.axes.Axes object

Axes object for this plot

sporco.plot.contour(z, x=None, y=None, v=5, xlog=False, ylog=False, xlbl=None, ylbl=None, title=None, cfmt=None, cfntsz=10, lfntsz=None, alpha=1.0, cmap=None, vmin=None, vmax=None, fgsz=None, fgnm=None, fig=None, ax=None)[source]

Contour plot of a 2D surface. If a figure object is specified then the plot is drawn in that figure, and fig.show() is not called. The figure is closed on key entry ‘q’.

Parameters
zarray_like

2d array of data to plot

xarray_like, optional (default None)

Values for x-axis of the plot

yarray_like, optional (default None)

Values for y-axis of the plot

vint or sequence of floats, optional (default 5)

An int specifies the number of contours to plot, and a sequence specifies the specific contour levels to plot.

xlogboolean, optional (default False)

Set x-axis to log scale

ylogboolean, optional (default False)

Set y-axis to log scale

xlblstring, optional (default None)

Label for x-axis

ylblstring, optional (default None)

Label for y-axis

titlestring, optional (default None)

Figure title

cfmtstring, optional (default None)

Format string for contour labels.

cfntszint or None, optional (default 10)

Contour label font size. No contour labels are displayed if set to 0 or None.

lfntszint, optional (default None)

Axis label font size. The default font size is used if set to None.

alphafloat, optional (default 1.0)

Underlying image display alpha value

cmapmatplotlib.colors.Colormap, optional (default None)

Colour map for surface. If none specifed, defaults to cm.YlOrRd

vmin, vmaxfloat, optional (default None)

Set upper and lower bounds for the colour map (see the corresponding parameters of matplotlib.axes.Axes.imshow)

fgsztuple (width,height), optional (default None)

Specify figure dimensions in inches

fgnminteger, optional (default None)

Figure number of figure

figmatplotlib.figure.Figure object, optional (default None)

Draw in specified figure instead of creating one

axmatplotlib.axes.Axes object, optional (default None)

Plot in specified axes instead of current axes of figure

Returns
figmatplotlib.figure.Figure object

Figure object for this figure

axmatplotlib.axes.Axes object

Axes object for this plot

sporco.plot.imview(img, title=None, copy=True, fltscl=False, intrp='nearest', norm=None, cbar=False, cmap=None, fgsz=None, fgnm=None, fig=None, ax=None)[source]

Display an image. Pixel values are displayed when the pointer is over valid image data. If a figure object is specified then the image is drawn in that figure, and fig.show() is not called. The figure is closed on key entry ‘q’.

Parameters
imgarray_like, shape (Nr, Nc) or (Nr, Nc, 3) or (Nr, Nc, 4)

Image to display

titlestring, optional (default None)

Figure title

copyboolean, optional (default True)

If True, create a copy of input img as a reference for displayed pixel values, ensuring that displayed values do not change when the array changes in the calling scope. Set this flag to False if the overhead of an additional copy of the input image is not acceptable.

fltsclboolean, optional (default False)

If True, rescale and shift floating point arrays to [0,1]

intrpstring, optional (default ‘nearest’)

Specify type of interpolation used to display image (see interpolation parameter of matplotlib.axes.Axes.imshow)

normmatplotlib.colors.Normalize object, optional (default None)

Specify the matplotlib.colors.Normalize instance used to scale pixel values for input to the colour map

cbarboolean, optional (default False)

Flag indicating whether to display colorbar

cmapmatplotlib.colors.Colormap, optional (default None)

Colour map for image. If none specifed, defaults to cm.Greys_r for monochrome image

fgsztuple (width,height), optional (default None)

Specify figure dimensions in inches

fgnminteger, optional (default None)

Figure number of figure

figmatplotlib.figure.Figure object, optional (default None)

Draw in specified figure instead of creating one

axmatplotlib.axes.Axes object, optional (default None)

Plot in specified axes instead of current axes of figure

Returns
figmatplotlib.figure.Figure object

Figure object for this figure

axmatplotlib.axes.Axes object

Axes object for this plot

sporco.plot.close(fig=None)[source]

Close figure(s). If a figure object reference or figure number is provided, close the specified figure, otherwise close all figures.

Parameters
figmatplotlib.figure.Figure object or integer, optional (default None)

Figure object or number of figure to close

sporco.plot.set_ipython_plot_backend(backend='qt')[source]

Set matplotlib backend within an ipython shell. Ths function has the same effect as the line magic %matplotlib [backend] but is called as a function and includes a check to determine whether the code is running in an ipython shell, so that it can safely be used within a normal python script since it has no effect when not running in an ipython shell.

Parameters
backendstring, optional (default ‘qt’)

Name of backend to be passed to the %matplotlib line magic command

sporco.plot.set_notebook_plot_backend(backend='inline')[source]

Set matplotlib backend within a Jupyter Notebook shell. Ths function has the same effect as the line magic %matplotlib [backend] but is called as a function and includes a check to determine whether the code is running in a notebook shell, so that it can safely be used within a normal python script since it has no effect when not running in a notebook shell.

Parameters
backendstring, optional (default ‘inline’)

Name of backend to be passed to the %matplotlib line magic command

sporco.plot.config_notebook_plotting()[source]

Configure plotting functions for inline plotting within a Jupyter Notebook shell. This function has no effect when not within a notebook shell, and may therefore be used within a normal python script.