Plot module

pygeode.plot

Module containing most plotting-related commands for PyGeode.

Top-level routines

showvar(var, *args, **kwargs)

Plot variable, showing a contour plot for 2d variables or a line plot for 1d variables.

showgrid(vf[, vl, ncol, size, lbl])

Create grid of contour plots of multiple variables.

showlines(vs[, fmts, labels, size, lblx, lbly])

Produce line plots of a list of 1D variables on a single figure.

Second-level routines

vplot(var[, fmt, axes, transpose, lblx, lbly])

Create a line plot of a variable.

vcontour(var[, clevs, clines, axes, lblx, ...])

Create a contour plot (lines, filled, or both) from a variable.

vscatter(varx, vary[, axes, lblx, lbly])

Create a scatter plot from two variables with the same shape.

vhist(var[, axes, lblx, lbly])

Create a histogram of values taken by a variable.

vsigmask(pval, axes[, mjsig, mnsig, mjsigp, ...])

Add significance shading to a contour plot from a variable.

vstreamplot(varu, varv[, axes, lblx, lbly, ...])

Create a streamplot from two variables.

vquiver(varu, varv[, varc, axes, lblx, ...])

Create a quiver plot from two variables.

Contouring helper functions

clfdict(cdelt[, min, mid, nf, nl, ndiv, ...])

Returns kwargs to showvar() for a filled contour plot.

cldict(cdelt[, range, min, mid, cidelt, nozero])

Returns kwargs to showvar() for a line contour plot.

log1sdict(cmin[, cdelt, nf, nl, ndiv])

Returns kwargs to showvar() for a one-sided logarithmically-spaced contour plot.

log2sdict(cmin[, cdelt, nf, nl, ndiv, nozero])

Returns kwargs to showvar() for a two-sided logarithmically-spaced contour plot.

Matplotlib wrappers

PyGeode uses a thin set of wrapper classes around matplotlib. The central object is the AxesWrapper class which provides an object that can produce a matplotlib plot. It was intended to make it possible to pickle and unpickle plots, though this often doesn’t work. Most of the higher-level plotting functions return an AxesWrapper instance.

The routines (most accessible as equivalent member functions of AxesWrapper) permit modifying and adding to plots much as one would with standard matplotlib figures. AxesWrappers can also be combined using into compound plots using plot.grid().

plot.AxesWrapper([parent, rect, size, pad, ...])

Methods

plot.plot(*args, **kwargs)

plot.fill_between(*args, **kwargs)

plot.scatter(*args, **kwargs)

plot.hist(*args, **kwargs)

plot.axhline(*args, **kwargs)

plot.axvline(*args, **kwargs)

plot.legend(*args, **kwargs)

plot.text(*args, **kwargs)

plot.colorbar(axes, cnt[, cax, rect])

plot.contour(*args, **kwargs)

plot.contourf(*args, **kwargs)

plot.quiver(*args, **kwargs)

plot.quiverkey(*args, **kwargs)

plot.grid(axes[, size])

pygeode.showvar(var, *args, **kwargs)[source]

Plot variable, showing a contour plot for 2d variables or a line plot for 1d variables.

Parameters
varVar

The variable to plot. Should have either 1 or 2 non-degenerate axes. Arguments below relevant only for the 1 dimensional case are labelled [1D], those relevant only for the 2 dimensional case are labelled [2D].

fmtstring, optional

[1D] matplotlib format to plot line. See matplotlib.plot(). Will also be recognized as the second positional argument (after var).

typestring, optional [‘clf’]

[2D] style of plot to produce. See Notes.

axesAxesWrapper instance, optional

Axes object on which to plot variable. A new one is created if this is not specified.

transpose: boolean, optional [False]

If True, reverse axes.

lblx: boolean, optional [True]

If True, label horizontal axes

lbly: boolean, optional [True]

If True, label vertical axes

*args, **kwargs :

Further arguments are passed on to the underlying plotting routine. See Notes.

Returns
AxesWrapper object with plot.

See also

vplot, vcontour, colorbar

Notes

This function is intended as the simplest way to display the contents of a variable, choosing appropriate parameter values as automatically as possible. For 1d variables it calls Var.vplot(), and for 2d variables Var.vcontour(). In the latter case, if filled contours were produced, it calls AxesWrapper.colorbar(). A dictionary colorbar can be provided to pass arguments through. Setting colorbar to False suppresses the colorbar.

pygeode.showgrid(vf, vl=[], ncol=1, size=(3.5, 1.5), lbl=True, **kwargs)[source]

Create grid of contour plots of multiple variables.

Parameters
vflist of lists of Var

The variables to plot. Should have 2 non-degenerate axes.

ncolinteger

Number of columns

pygeode.showlines(vs, fmts=None, labels=None, size=(4.1, 2), lblx=True, lbly=True, **kwargs)[source]

Produce line plots of a list of 1D variables on a single figure.

Parameters
vslist of Var

The variables to plot. Should all have 1 non-degenerate axis.

pygeode.vplot(var, fmt='', axes=None, transpose=False, lblx=True, lbly=True, **kwargs)[source]

Create a line plot of a variable.

Parameters
varVar

The variable to plot. Should have 1 non-degenerate axis.

fmtstring, optional

Format of the line. See pylab.plot().

pygeode.vcontour(var, clevs=None, clines=None, axes=None, lblx=True, lbly=True, label=True, transpose=None, **kwargs)[source]

Create a contour plot (lines, filled, or both) from a variable.

Parameters
varVar

The variable to plot. Should have 2 non-degenerate axes.

clevsinteger or collection of numbers, optional

Levels at which to construct filled contours through an underlying call to matplotlib.contourf(). If None is specified, no filled contours will be produced, unless clines is also None. If a number is specified, that number of equally spaced contours are chosen. Otherwise the explicit values are used.

clinesinteger or collection of numbers, optional

Levels at which to construct contour lines through an underlying call to matplotlib.contour(). If None is specified, no contour lines are produced. If a number is specified, that number of equally spaced contours are chosen. Otherwise the explicit values are used.

axesAxisWrapper, optional

Axes on which to produce contour plot. If none is specified, one is created.

lblxbool, optional

If True, add appropriate tick labels and an axis label on the x axis; if False, the x axis a is left unlabeled. Defaults to True.

lblybool, optional

If True, add appropriate tick labels and an axis label on the y axis; if False, the y axis a is left unlabeled. Defaults to True.

transposebool, optional

The x and y axes are chosen based on the two degenerate axes of the variable to plot. This order can be reversed by setting transpose to True.

mapdict, optional

If

*args, **kwargsarguments to pass on to underlying matplotlib contour

plotting routines, see Notes.

Returns
axesAxesWrapper

The axes object containing the contour plots.

See also

showvar, colorbar

Notes

If the two axes of the variable are a Lat and Lon axes, a map projection is created automatically.

pygeode.vscatter(varx, vary, axes=None, lblx=True, lbly=True, **kwargs)[source]

Create a scatter plot from two variables with the same shape.

Parameters
varxVar

Variable to use as abscissa values. Must have the same size as vary.

varyVar

Variable to use as ordinate values.

Notes

Wraps matplotlib.scatter

pygeode.vhist(var, axes=None, lblx=True, lbly=True, **kwargs)[source]

Create a histogram of values taken by a variable.

Parameters
varVar

The variable to compute the histogram of.

pygeode.vsigmask(pval, axes, mjsig=0.95, mnsig=None, mjsigp=None, mnsigp=None, nsigp=None, transpose=None)[source]

Add significance shading to a contour plot from a variable.

Parameters
pvalVar

The variable containing a p-value of the significance mask. The mask will be applied where abs(pval) > mjsig (and optionally an additional mask will be applied for mnsig < abs(pval) < mjsig. Signed p-values for two-sided tests ensure that a gap will appear between significant regions of opposite sign. Should have two non-degenerate axes that match the quantity plotted.

axesAxesWrapper

The axis on which to add the mask.

mjsigfloat, optional [0.95]

The p-value dividing significant from non-significant values.

mnsigfloat or None, optional [None]

The p-value dividing minor significance from non-significant values.

mjsigpdictionary, optional

A dictionary of keyword arguments that determine the properties of the (major) significant filled contours. See notes.

mnsigpdictionary, optional

A dictionary of keyword arguments that determine the properties of the minor significant filled contours. See notes.

nsigpdictionary, optional

A dictionary of keyword arguments that determine the properties of the non-significant filled contour. See notes.

transposebool or None, optional [None]

If True, transpose the axes of the plot.

Returns
AxesWrapper object with plot.

Notes

The significance mask is plotted as three (or five) filled contours, with boundaries at [-1.1, -mjsig, mjsig, 1.1] or [-1.1, -mjsig, -mnsig, mnsig, mjsig, 1.1]. Their respective graphical properties can be set using the dictionary kw arguments.

By default, the non-significant contours are set to be invisible and the significant contours are set to a hatching pattern; this is equivalent to passing in mjsigp = dict(alpha = 0., hatch = ‘…’) and nsigp = dict(visible = False). Any property of the filled contour can be set.

pygeode.vstreamplot(varu, varv, axes=None, lblx=True, lbly=True, label=True, transpose=None, **kwargs)[source]

Create a streamplot from two variables.

pygeode.vquiver(varu, varv, varc=None, axes=None, lblx=True, lbly=True, label=True, transpose=None, **kwargs)[source]

Create a quiver plot from two variables.

pygeode.clfdict(cdelt, min=None, mid=0.0, nf=6, nl=2, ndiv=3, nozero=False, style=None, clr=True, **kwargs)[source]

Returns kwargs to showvar() for a filled contour plot.

Parameters
cdeltfloat

Spacing of a single division. Each division is spanned by a certain number of filled contours and contour lines, and the colorbar will span a set number of divisions. See notes.

minfloat or None (optional)

If specified, contours span ndiv equal divisions starting with the value min. If None, the colorbar is centred on the value of mid. Default is None.

midfloat (optional)

If min is None, contours span ndiv equal divisions both above and below the value of mid.

nfinteger (optional)

Number of filled contours per division. Default is 6.

nlinteger (optional)

Number of contour lines per division. Default is 2.

nozeroboolean (optional)

If True, the contour line at mid is omitted. Defalt is False.

stylestring (optional)

Either ‘seq’ or ‘div’. Deterimines which style of colourmap to use; a sequential or divergent. Default is ‘div’, unless ‘’min’’ is set to something other than None.

pygeode.cldict(cdelt, range=None, min=None, mid=0, cidelt=0.0, nozero=False, **kwargs)[source]

Returns kwargs to showvar() for a line contour plot.

pygeode.log1sdict(cmin, cdelt=10.0, nf=6, nl=2, ndiv=5, **kwargs)[source]

Returns kwargs to showvar() for a one-sided logarithmically-spaced contour plot.

pygeode.log2sdict(cmin, cdelt=10, nf=6, nl=2, ndiv=3, nozero=False, **kwargs)[source]

Returns kwargs to showvar() for a two-sided logarithmically-spaced contour plot.

class pygeode.plot.AxesWrapper[source]

A PyGeode wrapper class for a matplotlib figure or subplot

pygeode.plot.grid(axes, size=None)[source]