healpix_plot.plot#

healpix_plot.plot(cell_ids, data, *, healpix_grid, sampling_grid, projection='Mollweide', view=None, agg='mean', interpolation='nearest', background_value=nan, rgb_clip=(0.0, 1.0), ax=None, title=None, colorbar=False, cmap='viridis', vmin=None, vmax=None, norm=None, axis_labels=None)[source]#

resample and plot healpix data

Parameters:
  • cell_ids (numpy.ndarray) – The cell ids describing the spatial position of the data.

  • data (numpy.ndarray) – The data to plot. If 1D, will be color-coded using the standard matplotlib mechanisms. If 2D, the last axis must have a size of 3 (for RGB) or 4 (for RGBA).

  • healpix_grid (HealpixGrid or dict of str to any) – The healpix grid parameters necessary to interpret cell_ids.

  • sampling_grid (SamplingGrid or dict of str to any) – The target grid.

  • projection (str or cartopy.crs.CRS) – The projection used to construct a new axis. Ignored if ax is given.

  • view (tuple of float, optional) – If given, defines the extent of the displayed plot.

  • agg (str, default: "mean") – Aggregation to deduplicate the data.

  • interpolation (str, default: "nearest") – The algorithm used to interpolate from healpix to the target grid. Available values:

    • "nearest": nearest-neighbour resampling

    • "bilinear": bilinear resampling

  • background_value (float, default: numpy.nan) – The background value for missing values.

  • ax (matplotlib.axis.Axis, optional) – The axis to plot on. If not passed, a new figure with a single axis is created using projection and figure_params.

  • vmin (float, optional) – Minimum value to color-code.

  • vmax (float, optional) – Maximum value to color-code.

  • norm (matplotlib.norm.Norm, optional) – Normalization class for more control.

  • cmap (str or matplotlib.colors.Colormap, default: "viridis") – The colormap to use for plotting.

  • axis_labels (dict of str to str or "none", optional) – Axis labels. Possible values:

    • if None or not passed, "Longitude" and "Latitude" are used.

    • dict: the keys "x" and "y" are used

    • "none": no axis labels

Returns:

mappable (matplotlib.image.AxisImage) – The mappable of the image to allow further processing.

Examples

>>> import healpix_plot
>>> import numpy as np

Define the source grid:

>>> healpix_params = healpix_plot.HealpixParameters(
...     level=4,
...     indexing_scheme="nested",
... )
>>> cell_ids = np.arange(12 * 4 ** healpix_params["level"], dtype="uint64")

Create the data:

>>> lon, lat = healpix_params.operations.healpix_to_lonlat(
...     cell_ids,
...     **healpix_params.as_keyword_params(),
... )
>>> data = np.cos(8 * np.deg2rad(lon)) * np.sin(4 * np.deg2rad(lat))

Plot the data

>>> healpix_plot.plot(
...     cell_ids,
...     data,
...     sampling_grid={"shape": 1024},
...     healpix_grid=healpix_params,
... )
<matplotlib.image.AxesImage at 0x...>