English | Deutsch

Plot functions

The plot function of each data type is documented on the page of the data type (All functions). This page describes what they share, and plot_raster(), which draws any GeoTIFF.

Shared options

Every plot function takes the file path and keyword options. It draws into a matplotlib Axes and returns it.

Option

Meaning

Available in

ax

the Axes to draw into; without it the function creates a figure

all

show

True: call plt.show() afterwards. Default: show only if the function created the figure

all

title

the title; None (default) gives the default title of the data type, "" no title

all

cmap

the matplotlib colour map

indices, temperature, soil water index, elevation

vmin, vmax

the value range of the colours; the defaults are fixed for the indices (-1 … 1) and the soil water index (0 … 100) and follow the image for temperature and elevation

the same

colorbar

False draws no colour bar

the same

What is drawn

  • Pixels without data are transparent.

  • The axes show the coordinates of the file: degrees or metres. For longitude and latitude the map is corrected for the shorter degrees of longitude (Grids and time).

  • A file with the wrong number of bands (for example a true-colour file passed to plot_ndvi) raises a ValueError that names the file and points to plot_raster.

Any GeoTIFF

cdec.plot_raster(file_path, *, band=1, cmap='viridis', vmin=None, vmax=None, label=None, title=None, colorbar=True, ax=None, show=None)[source]

Draw any GeoTIFF, decided by its format.

  • A file with three 8-bit bands is a colour picture (for example the true-colour image) and is drawn as it is.

  • Everything else is drawn as one band of numbers with a colour bar.

The function cannot know what the numbers mean. For the data types of this package use the matching function (plot_ndvi, plot_dem, …), which sets a suitable colour map and value range.

Parameters:
  • file_path (str | Path) – The GeoTIFF to draw, for example the file written by a download_* function.

  • band (int) – Which band to draw (1 is the first). Ignored for colour pictures.

  • cmap (str) – Name of a matplotlib colour map, see https://matplotlib.org/stable/users/explain/colors/colormaps.html

  • vmin (float | None) – Values at the two ends of the colour map. None takes the smallest and largest value of the band. Fix them (for example vmin=-1, vmax=1 for NDVI) to compare several images with the same colours.

  • vmax (float | None) – Values at the two ends of the colour map. None takes the smallest and largest value of the band. Fix them (for example vmin=-1, vmax=1 for NDVI) to compare several images with the same colours.

  • label (str | None) – Text next to the colour bar. Default: the description stored in the file, if there is one.

  • title (str | None) – Title of the plot.

  • colorbar (bool) – Draw a colour bar.

  • ax (Axes | None) – A matplotlib Axes to draw into. None creates a new figure.

  • show (bool | None) – Call plt.show() at the end. The default (None) shows the figure only if the function created it, so a figure that you put together yourself is not shown too early.

Returns:

The axes with the plot, for further changes.

Return type:

matplotlib.axes.Axes