API reference

NCPlot has one core function — view() — reachable three ways: directly from the top-level ncplot namespace, via the ncplot.xarray accessor, or from the ncplot command line tool.

Plotting
ncplot.view(x, vars=None, autoscale=True, out=None, **kwargs)

Plot the contents of a netCDF file, directory, remote URL, or xarray object.

Parameters

Required:

  • xrequired

    An xarray Dataset/DataArray, or a file path, directory, or remote (OPeNDAP/THREDDS) URL pointing to netCDF data.

Optional:

  • vars

    A variable name, or list of variable names, to plot. If omitted, every variable in x is plotted.

  • autoscale

    Whether colour scales are set automatically from each variable's minimum and maximum values. Default True. Set to False to keep scales fixed, e.g. when comparing several plots.

  • out

    Path to save the plot to, instead of displaying it inline. Must end in .html.

  • coast

    Draw coastlines on map plots. Default False. Looks best with the optional cartopy dependency installed (see Installing).

  • clim

    A (min, max) tuple fixing the colour scale range, overriding autoscale for that call.

Accessors
ncplot.xarray — Dataset.ncplot.view() / DataArray.ncplot.view()

Importing ncplot.xarray registers a .ncplot accessor on every xarray Dataset and DataArray, mirroring xarray's own .plot accessor:

python
import ncplot.xarray
import xarray as xr

ds = xr.open_dataset("example.nc")
ds.ncplot.view(vars="sst", coast=True)

Dataset.ncplot.view(vars=None, **kwargs) and DataArray.ncplot.view(vars=None, **kwargs) both call view() underneath with self as x — every keyword argument documented above works here too.

Command line
ncplot <file [file ...]>

Installing NCPlot adds an ncplot console command. Give it one or more existing file paths or URLs and it opens an interactive view — a single argument is passed straight to view(), multiple arguments are passed as a list:

console
$ ncplot example.nc
$ ncplot one.nc two.nc