metpy.plots
¶
Skew-T¶
-
class
metpy.plots.skewt.
SkewT
(fig=None, rotation=30, subplot=(1, 1, 1))¶ 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)
Creates SkewT - logP plots.
Parameters: - fig (matplotlib.figure.Figure, optional) – Source figure to use for plotting. If none is given, a new
matplotlib.figure.Figure
instance will be created. - rotation (float or int, optional) – Controls the rotation of temperature relative to horizontal. Given in degrees counterclockwise from x-axis. Defaults to 30 degrees.
- subplot (tuple[int, int, int] or matplotlib.gridspec.SubplotSpec instance, optional) – Controls the size/position of the created subplot. This allows creating
the skewT as part of a collection of subplots. If subplot is a tuple, it
should conform to the specification used for
matplotlib.figure.Figure.add_subplot()
. Thematplotlib.gridspec.SubplotSpec
can be created by usingmatplotlib.gridspec.GridSpec
.
-
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()
Returns: list[matplotlib.lines.Line2D] – lines plotted
See also
-
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()
Returns: matplotlib.quiver.Barbs – instance created
See also
-
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
Returns: matplotlib.collections.LineCollection – instance created
-
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
Returns: matplotlib.collections.LineCollection – instance created
-
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
Returns: matplotlib.collections.LineCollection – instance created
-
-
class
metpy.plots.skewt.
Hodograph
(ax=None, component_range=80)¶ Make a hodograph of wind data–plots the u and v components of the wind along the x and y axes, respectively.
This class simplifies the process of creating a hodograph using matplotlib. It provides helpers for creating a circular grid and for plotting the wind as a line colored by another value (such as wind speed).
-
ax
¶ matplotlib.axes.Axes – The underlying Axes instance used for all plotting
Create a Hodograph instance.
Parameters: - ax (matplotlib.axes.Axes, optional) – The Axes instance used for plotting
- component_range (value) – The maximum range of the plot. Used to set plot bounds and control the maximum number of grid rings needed.
-
add_grid
(increment=10.0, **kwargs)¶ Add grid lines to hodograph.
Creates lines for the x- and y-axes, as well as circles denoting wind speed values.
Parameters: - increment (value, optional) – The value increment between rings
- kwargs – Other kwargs to control appearance of lines
-
plot
(u, v, **kwargs)¶ Plot u, v data.
Plots the wind data on the hodograph.
Parameters: - u (array_like) – u-component of wind
- v (array_like) – v-component of wind
- kwargs – Other keyword arguments to pass to
matplotlib.axes.Axes.plot()
Returns: list[matplotlib.lines.Line2D] – lines plotted
See also
-
plot_colormapped
(u, v, c, **kwargs)¶ Plot u, v data, with line colored based on a third set of data.
Plots the wind data on the hodograph, but
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: - u (array_like) – u-component of wind
- v (array_like) – v-component of wind
- c (array_like) – data to use for colormapping
- kwargs – Other keyword arguments to pass to
matplotlib.collections.LineCollection
Returns: matplotlib.collections.LineCollection – instance created
See also
-
Station Plots¶
-
class
metpy.plots.station_plot.
StationPlot
(ax, x, y, fontsize=10, spacing=None, transform=None)¶ Make a standard meteorological station plot.
Plots values, symbols, or text spaced around a central location. Can also plot wind barbs as the center of the location.
Initialize the StationPlot with items that do not change.
This sets up the axes and station locations. The fontsize and spacing are also specified here to ensure that they are consistent between individual station elements.
Parameters: - ax (matplotlib.axes.Axes) – The
Axes
for plotting - x (array_like) – The x location of the stations in the plot
- y (array_like) – The y location of the stations in the plot
- fontsize (int) – The fontsize to use for drawing text
- spacing (int) – The spacing, in points, that corresponds to a single increment between station plot elements.
- transform (matplotlib.transforms.Transform (or compatible)) – The default transform to apply to the x and y positions when plotting.
-
location_names
= {'E': (1, 0), 'SW': (-1, -1), 'NE': (1, 1), 'W': (-1, 0), 'C': (0, 0), 'NW': (-1, 1), 'S': (0, -1), 'SE': (1, -1), 'N': (0, 1)}¶
-
plot_barb
(u, v, **kwargs)¶ At the center of the station model plot wind barbs.
Additional keyword arguments given will be passed onto matplotlib’s
barbs()
function; this is useful for specifying things like color or line width.Parameters: - u (array-like) – The data to use for the u-component of the barbs.
- v (array-like) – The data to use for the v-component of the barbs.
- kwargs – Additional keyword arguments to pass to matplotlib’s
barbs()
function.
See also
-
plot_parameter
(location, parameter, formatter='.0f', **kwargs)¶ At the specified location in the station model plot a set of values.
This specifies that at the offset location, the data in parameter should be plotted. The conversion of the data values to a string is controlled by formatter.
Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or font properties.
If something has already been plotted at this location, it will be replaced.
Parameters: - location (str or tuple[float, float]) – The offset (relative to center) to plot this parameter. If str, should be one of ‘C’, ‘N’, ‘NE’, ‘E’, ‘SE’, ‘S’, ‘SW’, ‘W’, or ‘NW’. Otherwise, should be a tuple specifying the number of increments in the x and y directions; increments are multiplied by spacing to give offsets in x and y relative to the center.
- parameter (array_like) – The numeric values that should be plotted
- formatter (str or callable, optional) – How to format the data as a string for plotting. If a string, it should be
compatible with the
format()
builtin. If a callable, this should take a value and return a string. Defaults to ‘0.f’. - kwargs – Additional keyword arguments to use for matplotlib’s plotting functions.
See also
-
plot_symbol
(location, codes, symbol_mapper, **kwargs)¶ At the specified location in the station model plot a set of symbols.
This specifies that at the offset location, the data in codes should be converted to unicode characters (for our
wx_symbol_font
) using symbol_mapper, and plotted.Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or font properties.
If something has already been plotted at this location, it will be replaced.
Parameters: - location (str or tuple[float, float]) – The offset (relative to center) to plot this parameter. If str, should be one of ‘C’, ‘N’, ‘NE’, ‘E’, ‘SE’, ‘S’, ‘SW’, ‘W’, or ‘NW’. Otherwise, should be a tuple specifying the number of increments in the x and y directions; increments are multiplied by spacing to give offsets in x and y relative to the center.
- codes (array_like) – The numeric values that should be converted to unicode characters for plotting.
- symbol_mapper (callable) – Controls converting data values to unicode code points for the
wx_symbol_font
font. This should take a value and return a single unicode character. Seemetpy.plots.wx_symbols
for included mappers. - kwargs – Additional keyword arguments to use for matplotlib’s plotting functions.
See also
-
plot_text
(location, text, **kwargs)¶ At the specified location in the station model plot a collection of text.
This specifies that at the offset location, the strings in text should be plotted.
Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or font properties.
If something has already been plotted at this location, it will be replaced.
Parameters: - location (str or tuple[float, float]) – The offset (relative to center) to plot this parameter. If str, should be one of ‘C’, ‘N’, ‘NE’, ‘E’, ‘SE’, ‘S’, ‘SW’, ‘W’, or ‘NW’. Otherwise, should be a tuple specifying the number of increments in the x and y directions; increments are multiplied by spacing to give offsets in x and y relative to the center.
- text (list (or array) of strings) – The strings that should be plotted
- kwargs – Additional keyword arguments to use for matplotlib’s plotting functions.
See also
- ax (matplotlib.axes.Axes) – The
-
class
metpy.plots.station_plot.
StationPlotLayout
¶ Encapsulates a standard layout for plotting using
StationPlot
.This class keeps a collection of offsets, plot formats, etc. for a parameter based on its name. This then allows a dictionary of data (or any object that allows looking up of arrays based on a name) to be passed to
plot()
to plot the data all at once.See also
-
class
PlotTypes
¶ Different plotting types for the layout.
Controls how items are displayed (e.g. converting values to symbols).
-
barb
= 4¶
-
symbol
= 2¶
-
text
= 3¶
-
value
= 1¶
-
-
StationPlotLayout.
add_barb
(u_name, v_name, units=None, **kwargs)¶ Add a wind barb to the center of the station layout.
This specifies that u- and v-component data should be pulled from the data container using the keys u_name and v_name, respectively, and plotted as a wind barb at the center of the station plot. If units are given, both components will be converted to these units.
Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or line width.
Parameters: - u_name (str) – The name of the parameter for the u-component for barbs, which is used as
a key to pull data out of the data container passed to
plot()
. - v_name (str) – The name of the parameter for the v-component for barbs, which is used as
a key to pull data out of the data container passed to
plot()
. - units (pint-compatible unit, optional) – The units to use for plotting. Data will be converted to this unit before conversion to a string. If not specified, no conversion is done.
- kwargs – Additional keyword arguments to use for matplotlib’s
barbs()
function.
See also
- u_name (str) – The name of the parameter for the u-component for barbs, which is used as
a key to pull data out of the data container passed to
-
StationPlotLayout.
add_symbol
(location, name, symbol_mapper, **kwargs)¶ Add a symbol to the station layout.
This specifies that at the offset location, data should be pulled from the data container using the key name and plotted. Data values will converted to glyphs appropriate for MetPy’s symbol font using the callable symbol_mapper.
Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or font properties.
Parameters: - location (str or tuple[float, float]) – The offset (relative to center) to plot this value. If str, should be one of ‘C’, ‘N’, ‘NE’, ‘E’, ‘SE’, ‘S’, ‘SW’, ‘W’, or ‘NW’. Otherwise, should be a tuple specifying the number of increments in the x and y directions.
- name (str) – The name of the parameter, which is used as a key to pull data out of the
data container passed to
plot()
. - symbol_mapper (callable) – Controls converting data values to unicode code points for the
wx_symbol_font
font. This should take a value and return a single unicode character. Seemetpy.plots.wx_symbols
for included mappers. - kwargs – Additional keyword arguments to use for matplotlib’s plotting functions.
See also
-
StationPlotLayout.
add_text
(location, name, **kwargs)¶ Add a text field to the station layout.
This specifies that at the offset location, data should be pulled from the data container using the key name and plotted directly as text with no conversion applied.
Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or font properties.
Parameters: - location (str or tuple(float, float)) – The offset (relative to center) to plot this value. If str, should be one of ‘C’, ‘N’, ‘NE’, ‘E’, ‘SE’, ‘S’, ‘SW’, ‘W’, or ‘NW’. Otherwise, should be a tuple specifying the number of increments in the x and y directions.
- name (str) – The name of the parameter, which is used as a key to pull data out of the
data container passed to
plot()
. - kwargs – Additional keyword arguments to use for matplotlib’s plotting functions.
See also
-
StationPlotLayout.
add_value
(location, name, fmt='.0f', units=None, **kwargs)¶ Add a numeric value to the station layout.
This specifies that at the offset location, data should be pulled from the data container using the key name and plotted. The conversion of the data values to a string is controlled by fmt. The units required for plotting can also be passed in using units, which will cause the data to be converted before plotting.
Additional keyword arguments given will be passed onto the actual plotting code; this is useful for specifying things like color or font properties.
Parameters: - location (str or tuple[float, float]) – The offset (relative to center) to plot this value. If str, should be one of ‘C’, ‘N’, ‘NE’, ‘E’, ‘SE’, ‘S’, ‘SW’, ‘W’, or ‘NW’. Otherwise, should be a tuple specifying the number of increments in the x and y directions.
- name (str) – The name of the parameter, which is used as a key to pull data out of the
data container passed to
plot()
. - fmt (str or callable, optional) – How to format the data as a string for plotting. If a string, it should be
compatible with the
format()
builtin. If a callable, this should take a value and return a string. Defaults to ‘0.f’. - units (pint-compatible unit, optional) – The units to use for plotting. Data will be converted to this unit before conversion to a string. If not specified, no conversion is done.
- kwargs – Additional keyword arguments to use for matplotlib’s plotting functions.
See also
-
StationPlotLayout.
names
()¶ Get the list of names used by the layout.
Returns: list[str] – the list of names of variables used by the layout
-
StationPlotLayout.
plot
(plotter, data_dict)¶ Plot a collection of data using this layout for a station plot.
This function iterates through the entire specified layout, pulling the fields named in the layout from data_dict and plotting them using plotter as specified in the layout. Fields present in the layout, but not in data_dict, are ignored.
Parameters: - plotter (StationPlot) –
StationPlot
to use to plot the data. This controls the axes, spacing, station locations, etc. - data_dict (dict[str, array-like]) – Data container that maps a name to an array of data. Data from this object will be used to fill out the station plot.
- plotter (StationPlot) –
-
class
-
metpy.plots.station_plot.
simple_layout
= {C: (symbol, cloud_coverage, ...), NE: (value, air_pressure_at_sea_level, ...), NW: (value, air_temperature, ...), SW: (value, dew_point_temperature, ...), W: (symbol, present_weather, ...), barb: (barb, ('eastward_wind', 'northward_wind'), ...)}¶ desc – Simple station plot layout
Colortables¶
-
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: matplotlib.colors.ListedColormap – The colortable corresponding to name
-
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: matplotlib.colors.BoundaryNorm, matplotlib.colors.ListedColormap – The boundary norm based on boundaries, and the colortable itself.
-
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: Returns: matplotlib.colors.BoundaryNorm, matplotlib.colors.ListedColormap – 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.
-
-
metpy.plots.ctables.
convert_gempak_table
(infile, outfile)¶ Convert a GEMPAK colortable to one MetPy can read.
Reads lines from a GEMPAK-style color table file, and writes them to another file in a format that MetPy can parse.
Parameters: - infile (file-like object) – The file-like object to read from
- outfile (file-like object) – The file-like object to write to
-
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: List of tuples – A list of the RGB color values, where each RGB color is a tuple of 3 floats in the range of [0, 1].