xoa.plot.plot_grid

Contents

xoa.plot.plot_grid#

xoa.plot.plot_grid(obj, ax=None, kind='mesh', stride='auto', min_spacing=None, edges=None, centers=None, strips=None, n_cells=1, transform=None, projection=None, map_kw=None, edge_kw=None, center_kw=None, scalebar=None, compass=None, **kwargs)[source]#

Plot a horizontal grid

A grid is made of cells whose centers are the points where the data are defined. Cell edges are computed from the centers with xoa.core.grid.centers2edges(), and both can be drawn, optionally over a field. Large grids are under-sampled to stay readable.

Parameters:
  • obj (xarray.DataArray, xarray.Dataset) – Object with longitude and latitude coordinates, that may be 1D or 2D. With the "mesh" and "resolution" kinds, the coordinates must be unambiguous, which means a single location on a staggered grid: pass a data array in case of doubt. With the "bathy" kind, the grid is the one of the bathymetry.

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

  • kind ({"mesh", "bathy", "resolution"}) –

    What to draw:

    • "mesh": only the edges and centers

    • "bathy": the bathymetry that is searched in obj with the "bathy" meta name and masked with the "mask" one if any. It falls back to the mesh with a warning if there is no bathymetry.

    • "resolution": the resolution computed with xoa.grid.get_resolution() as the geometric mean of the resolutions along x and y, in km.

  • stride (str, int, tuple(int)) – Under-sampling of the edges and centers, either one value for both directions or a (y, x) tuple. With "auto", the stride is adapted to the size of the axes and to the number of cells, so that there are at least min_spacing pixels between consecutive cells, measured on the map. When the grid is under-sampled, the drawn centers are the ones of the coarse cells delimited by the drawn edges.

  • min_spacing (None, float) – Minimal spacing in pixels between cells in the "auto" stride mode, which defaults to the plot.mesh_min_spacing option.

  • edges (None, bool) – Draw the edges of the cells. It defaults to True for the "mesh" kind, and to False with the others. The first and last edges are always drawn.

  • centers (None, bool) – Draw the centers of the cells. It defaults to True for the "mesh" kind, and to False with the others.

  • strips (None, str, list(str)) – Draw the extent of the strips along these edges. See xoa.grid.get_edge_extents().

  • n_cells (int) – Number of cells of the strips

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

  • projection (None, str, cartopy.crs.Projection) – Projection of the map when it is created, see xoa.core.plot.get_projection(). It has priority over the one of map_kw. The default is orthographic, centered on the grid, which limits the deformation of the cells.

  • map_kw (None, dict) – Parameters that decorate the map. See plot_field().

  • edge_kw (None, dict) – Parameters passed to matplotlib.collections.LineCollection to draw the edges, like colors or linewidths.

  • center_kw (None, dict) – Parameters passed to matplotlib.axes.Axes.plot() to draw the centers, like color or markersize.

  • scalebar (None, bool, dict) – Add a scale bar or a compass, see plot_field().

  • compass (None, bool, dict) – Add a scale bar or a compass, see plot_field().

  • kwargs – With the "bathy" and "resolution" kinds, extra parameters are passed to plot_field().

Returns:

cartopy.mpl.geoaxes.GeoAxes

Example

plot_grid(ds.temp)  # edges and centers, under-sampled if needed
plot_grid(ds.temp, stride=(2, 4), centers=False)
plot_grid(ds, kind="bathy", edges=True, strips="north")