uxarray.UxDataArray.plot.contour

uxarray.UxDataArray.plot.contour#

UxDataArray.plot.contour(levels=7, method=None, backend=None, projection=None, labels=True, hover=True, **kwargs)#

Generate a contour line plot.

The contour lines are computed on the unstructured grid itself, without regridding the data.

See examples in Contour Demos.

Parameters:
  • levels (int or sequence of float, default=7) – If an integer, roughly that many contour levels are chosen at round values within the range of the data. If a sequence, contour lines are drawn at those values.

  • method (str, optional) –

    How the contour lines are computed. Defaults to “edges” for face-centered data and “interpolated” for node-centered data. Options are:

    • ”edges”: Lines follow the edges of the grid that separate faces above a level from faces at or below it, without interpolation. Supported for face-centered data.

    • ”interpolated”: The data is linearly interpolated between the locations it is defined on, which gives smooth lines. Supported for face-centered and node-centered data.

  • backend (str or None, optional) – Plotting backend to use. One of [‘matplotlib’, ‘bokeh’]. Equivalent to running holoviews.extension(backend)

  • projection (ccrs.Projection, optional) – The map projection to use. Pass the same projection as the plot the contours are overlaid on, if one was used for a plot below.

  • labels (bool or float, default=True) – Whether the lines are labeled with their level. Each level is labeled at the middle of its longest lines. A number between 0 and 1 labels that fraction of the levels, spread evenly from the lowest one: 0.5 labels every second level. 0 is the same as False.

  • hover (bool, default=True) – Whether the level of a line is shown when the pointer is over it. This applies to the Bokeh backend; Matplotlib plots are static images.

  • **kwargs (dict) – Additional options for the lines, such as color, line_width or cmap. As with the other plot methods, options are given with their Bokeh names on both backends.

Returns:

contours – The contour lines, one path per line with the contour level as its value, overlaid with their labels. With labels=False the lines alone: an hv.Contours, or a gv.Contours if a projection is given.

Return type:

hv.Overlay, hv.Contours or gv.Contours

Raises:
  • DataCenteringError (subclass of ValueError) – If the data is not mapped to the faces or nodes of the grid, or if method="edges" is used with data that is not face-centered.

  • DimensionError (subclass of ValueError) – If the data has more than one dimension that is not of length 1.

  • ValueError – If an option in **kwargs is not an option of the lines, or if labels is not True, False or a number between 0 and 1.

Notes

Contour lines are split where they cross the antimeridian.

Lines stop where neighbouring faces do not share their nodes, as on grids that store the same node more than once (for example along the panel seams of some cubed-sphere grids).

Data that has no grid dimension, such as a mean over the faces, is passed to xarray.DataArray.plot.contour() with levels and **kwargs.

Examples

Overlay black contour lines on a shaded plot of the same variable

>>> uxds["psi"].plot() * uxds["psi"].plot.contour(color="black")

Draw smooth contours of one variable over another, at chosen levels

>>> uxds["wind"].plot() * uxds["mslp"].plot.contour(
...     levels=[980, 990, 1000, 1010], method="interpolated", color="black"
... )