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()andxoa.coords.get_lat(), and the extent of the map is computed withxoa.geo.get_extent(). The colorbar is labelled withget_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 theplot.field_methodoptiontransform (None, cartopy.crs.CRS) – Coordinate system of the field, which defaults to
PlateCarreetitle (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(). Whenaxis not provided,figsizeandprojectionare also accepted, as increate_map().overlay_contours (None, True, list(dict)) – Line contours drawn over the field.
Trueis a shorthand for a single contour of the field. Each item is a dict of parameters passed tomatplotlib.axes.Axes.contour(), with an extrafieldkey, which is either a data array on any grid, a generic meta name like"bathy"or"mask"that is searched indswithxoa.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()oradd_compass(). A dict gives their parameters, likeloc,styleoreffect.compass (None, bool, dict) – Add a scale bar or a compass with
add_scalebar()oradd_compass(). A dict gives their parameters, likeloc,styleoreffect.kwargs – Extra parameters are passed to the plot method, like
cmap,vmin,vmaxoradd_colorbar. The colorbar is shrunk by default, which can be changed withcbar_kwargs. Withcmap="auto", the colormap is chosen from the sign of the data among theplot.cmapdiv,plot.cmapposandplot.cmapnegoptions, 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)
See also