Plotting

metpy.plots

class metpy.plots.SkewT(fig=None, rotation=30)

Make Skew-T log-P plots of data

This class simplifies the process of creating Skew-T log-P plots in using matplotlib. It handles requesting the appropriate skewed projection, and provides simplified wrappers to make it easy to plot data, add wind barbs, and add other lines to the plots (e.g. dry adiabats)

ax

matplotlib.axes.Axes – The underlying Axes instance, which can be used for calling additional plot functions (e.g. axvline)

plot(p, t, *args, **kwargs)

Plot data.

Simple wrapper around plot so that pressure is the first (independent) input. This is essentially a wrapper around semilogy. It also sets some appropriate ticking and plot ranges.

Parameters:
  • p (array_like) – pressure values
  • t (array_like) – temperature values, can also be used for things like dew point
  • args – Other positional arguments to pass to semilogy
  • kwargs – Other keyword arguments to pass to semilogy

See also

matplotlib.Axes.semilogy

plot_barbs(p, u, v, xloc=1.0, x_clip_radius=0.08, y_clip_radius=0.08, **kwargs)

Plot wind barbs.

Adds wind barbs to the skew-T plot. This is a wrapper around the barbs command that adds to appropriate transform to place the barbs in a vertical line, located as a function of pressure.

Parameters:
  • p (array_like) – pressure values
  • u (array_like) – U (East-West) component of wind
  • v (array_like) – V (North-South) component of wind
  • xloc (float, optional) – Position for the barbs, in normalized axes coordinates, where 0.0 denotes far left and 1.0 denotes far right. Defaults to far right.
  • x_clip_radius (float, optional) – Space, in normalized axes coordinates, to leave before clipping wind barbs in the x-direction. Defaults to 0.08.
  • y_clip_radius (float, optional) – Space, in normalized axes coordinates, to leave above/below plot before clipping wind barbs in the y-direction. Defaults to 0.08.
  • kwargs – Other keyword arguments to pass to barbs

See also

matplotlib.Axes.barbs

plot_dry_adiabats(t0=None, p=None, **kwargs)

Plot dry adiabats.

Adds dry adiabats (lines of constant potential temperature) to the plot. The default style of these lines is dashed red lines with an alpha value of 0.5. These can be overridden using keyword arguments.

Parameters:
  • t0 (array_like, optional) – Starting temperature values in Kelvin. If none are given, they will be generated using the current temperature range at the bottom of the plot.
  • p (array_like, optional) – Pressure values to be included in the dry adiabats. If not specified, they will be linearly distributed across the current plotted pressure range.
  • kwargs – Other keyword arguments to pass to matplotlib.collections.LineCollection

See also

plot_moist_adiabats matplotlib.collections.LineCollection metpy.calc.dry_lapse

plot_mixing_lines(w=None, p=None, **kwargs)

Plot lines of constant mixing ratio.

Adds lines of constant mixing ratio (isohumes) to the plot. The default style of these lines is dashed green lines with an alpha value of 0.8. These can be overridden using keyword arguments.

Parameters:
  • w (array_like, optional) – Unitless mixing ratio values to plot. If none are given, default values are used.
  • p (array_like, optional) – Pressure values to be included in the isohumes. If not specified, they will be linearly distributed across the current plotted pressure range up to 600 mb.
  • kwargs – Other keyword arguments to pass to matplotlib.collections.LineCollection

See also

matplotlib.collections.LineCollection

plot_moist_adiabats(t0=None, p=None, **kwargs)

Plot moist adiabats.

Adds saturated pseudo-adiabats (lines of constant equivalent potential temperature) to the plot. The default style of these lines is dashed blue lines with an alpha value of 0.5. These can be overridden using keyword arguments.

Parameters:
  • t0 (array_like, optional) – Starting temperature values in Kelvin. If none are given, they will be generated using the current temperature range at the bottom of the plot.
  • p (array_like, optional) – Pressure values to be included in the moist adiabats. If not specified, they will be linearly distributed across the current plotted pressure range.
  • kwargs – Other keyword arguments to pass to matplotlib.collections.LineCollection

See also

plot_dry_adiabats matplotlib.collections.LineCollection metpy.calc.moist_lapse

Colortables

metpy.plots.ctables

class metpy.plots.ctables.ColortableRegistry

Manages the collection of colortables.

Provides access to colortables, read collections of files, and generates matplotlib’s Normalize instances to go with the colortable.

add_colortable(fobj, name)

Add a colortable from a file to the registry

Parameters:
  • fobj (file-like object) – The file to read the colortable from
  • name (str) – The name under which the colortable will be stored
get_colortable(name)

Get a colortable from the registry

Parameters:name (str) – The name under which the colortable will be stored
Returns:The colortable corresponding to name
Return type:matplotlib.colors.ListedColormap
get_with_boundaries(name, boundaries)

Get a colortable from the registry with a corresponding norm.

Builds a matplotlib.colors.BoundaryNorm using boundaries.

Parameters:
  • name (str) – The name under which the colortable will be stored
  • boundaries (array_like) – The list of boundaries for the norm
Returns:

The boundary norm based on boundaries, and the colortable itself.

Return type:

matplotlib.colors.BoundaryNorm, matplotlib.colors.ListedColormap

get_with_steps(name, start, step)

Get a colortable from the registry with a corresponding norm.

Builds a matplotlib.colors.BoundaryNorm using start, step, and the number of colors, based on the colortable obtained from name.

Parameters:
  • name (str) – The name under which the colortable will be stored
  • start (float) – The starting boundary
  • step (float) – The step between boundaries
Returns:

The boundary norm based on start and step with the number of colors from the number of entries matching the colortable, and the colortable itself.

Return type:

matplotlib.colors.BoundaryNorm, matplotlib.colors.ListedColormap

scan_dir(path)

Scan a directory on disk for colortable files and add them to the registry

Parameters:path (str) – The path to the directory with the colortables
scan_resource(pkg, path)

Scan a resource directory for colortable files and add them to the registry

Parameters:
  • pkg (str) – The package containing the resource directory
  • path (str) – The path to the directory with the colortables
metpy.plots.ctables.read_colortable(fobj)

Read colortable information from a file

Reads a colortable, which consists of one color per line of the file, where a color can be one of: a tuple of 3 floats, a string with a HTML color name, or a string with a HTML hex color.

Parameters:fobj (a file-like object) – A file-like object to read the colors from
Returns:A list of the RGB color values, where each RGB color is a tuple of 3 floats in the range of [0, 1].
Return type:List of tuples