xoa.plot.plot_field

Contents

xoa.plot.plot_field#

xoa.plot.plot_field(field, ax=None, method=None, transform=None, title=None, margin=0.0, map_kw=None, overlay_contours=None, ds=None, scalebar=None, compass=None, **kwargs)[source]#

Plot a field on a map

Longitudes and latitudes are found with xoa.coords.get_lon() and xoa.coords.get_lat(), and the extent of the map is computed with xoa.geo.get_extent(). The colorbar is labelled with get_label().

Parameters:
  • field (xarray.DataArray) – Field with longitude and latitude coordinates, and no other dimension than the horizontal ones.

  • ax (None, cartopy.mpl.geoaxes.GeoAxes) – Axes to plot on. A map is created if not provided.

  • method (None, {"pcolormesh", "contourf", "contour"}) – Plot method of xarray.DataArray.plot, which defaults to the plot.field_method option

  • transform (None, cartopy.crs.CRS) – Coordinate system of the field, which defaults to PlateCarree

  • title (None, str)

  • margin (float) – Margin added to the extent. See xoa.geo.get_extent().

  • map_kw (None, dict) – Parameters that decorate the map, as accepted by decorate_map(). When ax is not provided, figsize and projection are also accepted, as in create_map().

  • overlay_contours (None, True, list(dict)) – Line contours drawn over the field. True is a shorthand for a single contour of the field. Each item is a dict of parameters passed to matplotlib.axes.Axes.contour(), with an extra field key, which is either a data array on any grid, a generic meta name like "bathy" or "mask" that is searched in ds with xoa.meta, or the plotted field by default. Colors default to black.

  • ds (None, xarray.Dataset) – Dataset where the meta names of overlay fields are searched

  • scalebar (None, bool, dict) – Add a scale bar or a compass with add_scalebar() or add_compass(). A dict gives their parameters, like loc, style or effect.

  • compass (None, bool, dict) – Add a scale bar or a compass with add_scalebar() or add_compass(). A dict gives their parameters, like loc, style or effect.

  • kwargs – Extra parameters are passed to the plot method, like cmap, vmin, vmax or add_colorbar. The colorbar is shrunk by default, which can be changed with cbar_kwargs. With cmap="auto", the colormap is chosen from the sign of the data among the plot.cmapdiv, plot.cmappos and plot.cmapneg options, and the limits of the diverging colormap are made symmetric.

Returns:

matplotlib.cm.ScalarMappable – The artist returned by the plot method

Example

plot_field(ds.temp.isel(time=0), cmap="Spectral_r",
           overlay_contours=[dict(field="bathy", levels=[100, 1000])], ds=ds)