eumap.plotter.plot_rasters

plot_rasters(*rasters, out_file=None, vertical_layout=False, figsize=10, spacing=0.01, cmaps='Spectral', titles=[], dpi=150, nodata=None, vmin=None, vmax=None, perc_clip=False, perc_min=2, perc_max=98)[source]

Plots data from one or more rasters.

Preserves pixel aspect ratio, removes axes and ensures transparency on nodata.

Uses matplotlib.pyplot.imshow [1].

Parameters
  • *rasters

    List of rasters, passed as either data or file paths. If 3D (multiband) data is passed (as numpy array(s)), the first axis of the array must correspond to the band index.

  • out_file (Union[str, Path, None]) – Path to save figure if not None.

  • vertical_layout (bool) – Produces a vertical array of plots if True, horizontal if False (default).

  • figsize (float) – Print size of the horizontal axis of the plot (passed to matplotlib). The vertical size is calculated automatically.

  • spacing (float) – Spacing between raster plots.

  • cmaps (Union[str, List[str]]) – Colormap to use for singleband plots, or list of colormaps (applied respectively). Must contain valid matplotlib colormaps [2]. For rasters with multiple (3 or more) bands, this argument is ignored and RGB plots are produced.

  • titles (List[str]) – Titles to produce for each plot.

  • dpi (int) – DPI of the figure.

  • nodata (Optional[List[Union[int, float]]]) – Nodata value or list of values respective to each raster. If None and *rasters contains file paths, nodata will be inferred from raster source.

  • vmin (Optional[List[Union[int, float]]]) – Minimum value to clip data.

  • vmax (Optional[List[Union[int, float]]]) – Maximum value to clip data.

  • perc_clip (bool) – Clips rasters with percentiles if True.

  • perc_min (List[Union[int, float]]) – Minimum percentile to clip with if perc_clip=True.

  • perc_max (List[Union[int, float]]) – Maximum percentile to clip with if perc_clip=True.

References

[1] Matplotlib imshow

[2] Matplotlib colormaps

Examples

>>> from eumap import plotter
>>> import numpy as np
>>>
>>> singleband = np.random.randint(0, 255, [5, 5])
>>> multiband = np.random.randint(0, 255, [3, 5, 5])
>>>
>>> plotter.plot_rasters(
>>>     singleband,
>>>     multiband,
>>>     titles=['single band', 'RGB'],
>>>     figsize=4,
>>>     cmaps='Greens',
>>> )