Plotting#

This section introduces UXarray’s plotting API, showcasing how to visualize both data variables and grid topology.

import uxarray as ux

Data#

For most of the examples in this notebook, we will be using a simple mesh consisting of 4 hexagons, with sample data mapped to the faces, edges, and nodes.

grid_path = "../../test/meshfiles/ugrid/quad-hexagon/grid.nc"

data_paths = [
    "../../test/meshfiles/ugrid/quad-hexagon/random-node-data.nc",
    "../../test/meshfiles/ugrid/quad-hexagon/random-edge-data.nc",
    "../../test/meshfiles/ugrid/quad-hexagon/random-face-data.nc",
]

uxds = ux.open_mfdataset(grid_path, data_paths)
uxgrid = uxds.uxgrid

uxds
<xarray.UxDataset> Size: 312B
Dimensions:           (n_edge: 19, n_face: 4, n_node: 16)
Dimensions without coordinates: n_edge, n_face, n_node
Data variables:
    random_data_edge  (n_edge) float64 152B dask.array<chunksize=(19,), meta=np.ndarray>
    random_data_face  (n_face) float64 32B dask.array<chunksize=(4,), meta=np.ndarray>
    random_data_node  (n_node) float64 128B dask.array<chunksize=(16,), meta=np.ndarray>

Grid Topology Visualization#

The topology (i.e. edges and coordinates) of an unstructured grid can be plotted using the Grid.plot() accessor. By default, Grid.plot() will plot the edges of the unstructured grid.

uxgrid.plot(title="Grid Plot Accessor")

Edge Plots#

The default plotting routine above calls the Grid.edges() method, which visualizes the edges of each face in the unstructured grid.

uxgrid.plot.edges(color="black", title="Grid Edge Plot")

Point Plots#

There are three coordinates that are typically associated with unstructured grids:

  • Corner Nodes: node_lon & node_lat

  • Edge Centers: edge_lon & edge_lat

  • Face Centers: face_lon & face_lat

These coordinates can be plotted using the following plotting methods:

  • Corner Nodes: Grid.plot.nodes()

  • Edge Centers: Grid.plot.edge_centers()

  • Face Centers: Grid.plot.face_centers()

(
    uxgrid.plot.edges(color="black")
    * uxgrid.plot.nodes(marker="o", size=150).relabel("Corner Nodes")
    * uxgrid.plot.face_centers(marker="s", size=150).relabel("Face Centers")
    * uxgrid.plot.edge_centers(marker="^", size=150).relabel("Edge Centers")
).opts(title="Grid Coordinates", legend_position="top_right")

Data Visualization#

Visualizing Data#

The section above visualized the topology an unstructured grid. If you are working with data residing on an unstructured grid, plotting is handled through the UxDataArray.plot() accessor.

uxds["random_data_face"].plot(
    cmap=ux.cmaps.diverging, title="UxDataArray Plot Accessor"
)