Plotting#
For a worked, example-driven walkthrough see the Plotting NetCDF data tutorial. This page is the API reference (signature table + the auto-generated
Selectors/CoordinateSpec/FacetSpecdocs).
NetCDF.plot mirrors Dataset.plot's signature. You pick a variable, slice along the
non-spatial dimensions, pass faceting / coordinate options through small grouped, frozen dataclasses
(Selectors, CoordinateSpec, FacetSpec) re-exported from pyramids.netcdf, and express colour
exactly as Dataset.plot does — through loose keyword arguments plus the shared cleopatra render bags.
The option bags and loose kwargs feed NetCDF.plot, which is a thin facade over NetCDFPlot (_plot.py). That
resolves the variable/slice and hands the array to the shared render_array core (_plot_helpers.py)
— the same renderer behind Dataset.plot and DatasetCollection.plot — which draws into a cleopatra
ArrayGlyph and returns the glyph (.fig / .ax / .im):
flowchart LR
SEL["Selectors<br/>time · level · member<br/>sel · isel"]
AXES["CoordinateSpec<br/>coords · x_dim · y_dim"]
FAC["FacetSpec<br/>col · row · col_wrap"]
KW["loose colour kwargs<br/>cmap · vmin · vmax · robust<br/>levels · norm · center · extend"]
SEL --> P["NetCDF.plot(variable, ...)"]
AXES --> P
FAC --> P
KW --> P
P --> NP["NetCDFPlot<br/>(_plot.py)"]
NP --> RA["render_array<br/>(_plot_helpers.py)"]
RA --> CG(["cleopatra ArrayGlyph"])
CG --> FIG[("glyph<br/>.fig · .ax · .im")]
Colour is expressed exactly as on
Dataset.plot— via loose keyword arguments (cmap,vmin,vmax,robust,center,extend,levels,norm) plus the cleopatra render bags (colorbar=,color=,contour=,cells=,data_style=). There is no dedicated colour-options parameter — the colour knobs are loose kwargs, andcolorbar=Falsehides the colour bar.
from pyramids.netcdf import NetCDF, Selectors, CoordinateSpec, FacetSpec
nc = NetCDF.read_file("era5.nc")
# pick a variable, select along non-spatial dims, labeled-array-style colour kwargs
nc.plot("t2m", selectors=Selectors(time="2020-01-01 12:00:00", level=850),
cmap="coolwarm", robust=True)
# curvilinear (WRF) grid -> pcolormesh, faceted over time
nc.plot("T2", axes=CoordinateSpec(coords=(XLONG, XLAT)), kind="pcolormesh",
facet=FacetSpec(col="time", col_wrap=4))
# animate over a dimension with lazy, per-frame reads ([lazy] extra)
nc.plot("t2m", animate="time", chunks={"time": 1})
Signature#
NetCDF.plot(variable=None, *, selectors=None, facet=None, axes=None, kind="auto",
animate=None, chunks=None, basemap=None, exclude_value=None, title=None, **kwargs)
| Parameter | Type | Notes |
|---|---|---|
variable |
str, optional |
Variable to plot; defaults to the dataset's single / active variable. |
selectors |
Selectors, optional |
Pin non-spatial dims: time=, level=, member=, sel=, isel=, method= |
facet |
FacetSpec, optional |
Small-multiples grid — col=, row=, col_wrap=. |
axes |
CoordinateSpec, optional |
Curvilinear coords / dimension names — coords=(x_2d, y_2d) (-> pcolormesh), x_dim=, y_dim=. Auto-detected from CF / WRF / ROMS / NEMO when omitted. |
kind |
str, optional |
"auto", "imshow", "pcolormesh", "contour", "contourf". |
animate |
bool or str, optional |
Animate over a dimension (its name, or True for the leading non-spatial dimension). |
chunks |
dict, optional |
Dask chunking — switches to a lazy read; only the rendered slice / frame is materialised. Requires the [lazy] extra. |
basemap |
bool or str, optional |
Overlay a web-tile basemap (provider name as a string, e.g. "CartoDB.Positron"). Requires the [viz] extra. |
**kwargs |
Colour, exactly as Dataset.plot: loose kwargs (cmap, vmin, vmax, robust, center, extend, levels, norm) + cleopatra bags colorbar= (ColorBar(...) / False), color=, contour=, cells=, data_style=; plus ax, figsize. |
Selectors forwards its selectors to NetCDF.sel, so they take the same two vocabularies: a time=
selector may be the stored CF offset or a decoded date label. A label names a period, so its precision
decides how much it pins — "2020-01-01 12:00:00" is one step, "2020-01-01" the whole day, "2020-01"
the whole month. get_time_variable() reports date-only labels unless asked for a finer
time_format, so pass "%Y-%m-%d %H:%M:%S" when you need a label that pins a single slice.
method="nearest" snaps each numeric selector to the closest coordinate on its axis; label
selectors on other dims are unaffected and stay exact.
See Dimension coordinates and selection.
The GeoTIFF-only kwargs band, rgb, surface_reflectance, cutoff, percentile, overview,
and overview_index are not accepted on NetCDF.plot — passing any of them raises TypeError
with a hint pointing at the replacement above (use selectors= to pick a slice, loose colour kwargs
such as cmap= / robust= for the colour scale, and so on).
Internally NetCDF.plot is a thin facade over pyramids.netcdf._plot.NetCDFPlot, which shares the
pyramids.dataset._plot_helpers.render_array rendering core with Dataset.plot and
DatasetCollection.plot (and mesh_render with UgridDataset.plot). The full rendered method
signature and docstring are on the NetCDF Class reference page.
Option dataclasses#
pyramids.netcdf.Selectors
dataclass
#
Dimension selectors for :meth:NetCDF.plot.
Groups the label-based dimension selectors that pin a multi-dim
NetCDF variable to a single 2-D slice. All fields are optional;
pass only the dims that need pinning. Convenience aliases
(time / level / member) auto-detect the matching band
dim name; raw sel / isel dicts take the dim name verbatim.
Attributes:
| Name | Type | Description |
|---|---|---|
time |
Any
|
Convenience label selector for the time dim. Equivalent
to |
level |
Any
|
Convenience label selector for the vertical dim
(auto-detected as the first of
|
member |
Any
|
Convenience label selector for the ensemble dim
( |
sel |
dict[str, Any] | None
|
Raw label selectors forwarded directly to
:meth: |
isel |
dict[str, int] | None
|
Positional selectors keyed by dim name. Each int is converted to the corresponding coord value via the variable's band-dim coord map; dims without coord values receive the int unchanged. Defaults to None. Not the same thing as :meth: |
method |
Literal['nearest'] | None
|
How the selectors above are matched — |
Examples:
-
The default constructor produces an all-
Noneinstance that is safe to forward toplotunchanged: -
Pin both the time and pressure-level dims of a 4-D variable:
-
Ask for the level nearest a target rather than an exact one:
-
An unknown matching mode is refused at construction, not part-way through a render:
-
Frozen instances reject attribute assignment so the option bag stays stable after construction:
Source code in src/pyramids/netcdf/plot_options.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
__post_init__()
#
Reject an unknown method where the caller typed it, not mid-render.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/plot_options.py
pyramids.netcdf.CoordinateSpec
dataclass
#
How a NetCDF variable's spatial axes are interpreted, for :meth:NetCDF.plot.
Groups the three axis-related plot options into one bag: an explicit curvilinear (x, y)
2-D coordinate pair, or the names of the x / y dimensions when they cannot be
auto-resolved from CF attributes. All fields default to None (auto-detect).
Attributes:
| Name | Type | Description |
|---|---|---|
coords |
tuple | list | None
|
Explicit |
x_dim |
str | None
|
Name of the |
y_dim |
str | None
|
Name of the |
Examples:
-
A curvilinear coordinate pair:
-
Explicit dimension names:
Source code in src/pyramids/netcdf/plot_options.py
pyramids.netcdf.FacetSpec
dataclass
#
Faceting specification for :meth:NetCDF.plot.
When set, NetCDF.plot builds a stack of slices along the named
dims and hands them to
:meth:cleopatra.glyphs.gridded.array_glyph.ArrayGlyph.facet. At least one of
col or row must be set; row alone (without col) is
invalid and rejected by the validator.
Attributes:
| Name | Type | Description |
|---|---|---|
col |
str | None
|
Band-dim name to facet across columns. Defaults to None. |
row |
str | None
|
Band-dim name to facet across rows. Requires |
col_wrap |
int | None
|
When only |
Examples:
-
A column-only facet over the time dim:
-
Two-axis facet across time (columns) and pressure level (rows):
-
Column-wrap layout — 4 panels in a 2x3 grid: