Plot module¶
pygeode.plot
Module containing most plotting-related commands for PyGeode.
Top-level routines
|
Plot variable, showing a contour plot for 2d variables or a line plot for 1d variables. |
|
Create grid of contour plots of multiple variables. |
|
Produce line plots of a list of 1D variables on a single figure. |
Second-level routines
|
Create a line plot of a variable. |
|
Create a contour plot (lines, filled, or both) from a variable. |
|
Create a scatter plot from two variables with the same shape. |
|
Create a histogram of values taken by a variable. |
|
Add significance shading to a contour plot from a variable. |
|
Create a streamplot from two variables. |
|
Create a quiver plot from two variables. |
Contouring helper functions
|
Returns kwargs to |
|
Returns kwargs to |
|
Returns kwargs to |
|
Returns kwargs to |
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()
.
|
Methods |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- pygeode.showvar(var, *args, **kwargs)[source]¶
Plot variable, showing a contour plot for 2d variables or a line plot for 1d variables.
- Parameters
- var
Var
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.
- axes
AxesWrapper
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.
- var
- Returns
AxesWrapper
object with plot.
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 variablesVar.vcontour()
. In the latter case, if filled contours were produced, it callsAxesWrapper.colorbar()
. A dictionarycolorbar
can be provided to pass arguments through. Settingcolorbar
toFalse
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
- vflist of lists of
- 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.
- vslist of
- pygeode.vplot(var, fmt='', axes=None, transpose=False, lblx=True, lbly=True, **kwargs)[source]¶
Create a line plot of a variable.
- Parameters
- var
Var
The variable to plot. Should have 1 non-degenerate axis.
- fmtstring, optional
Format of the line. See
pylab.plot()
.
- var
- 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
- var
Var
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.- axes
AxisWrapper
, 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.
- var
- Returns
- axes
AxesWrapper
The axes object containing the contour plots.
- axes
See also
showvar
,colorbar
Notes
If the two axes of the variable are a
Lat
andLon
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
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
- var
Var
The variable to compute the histogram of.
- var
- 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
- pval
Var
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.
- axes
AxesWrapper
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.
- pval
- 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.