rasterio.plot module

Implementations of various common operations.

Including show() for displaying an array or with matplotlib. Most can handle a numpy array or rasterio.Band(). Primarily supports $ rio insp.

rasterio.plot.adjust_band(band, kind='linear')

Adjust a band to be between 0 and 1.

  • band (array, shape (height, width)) – A band of a raster object.

  • kind ('linear') – The kind of normalization to apply. For now, there is only one option (‘linear’).


band_normed – An adjusted version of the input band.

Return type

array, shape (height, width)


import matplotlib.pyplot raise import error if matplotlib is not installed

rasterio.plot.plotting_extent(source, transform=None)
Returns an extent in the format needed

for matplotlib’s imshow (left, right, bottom, top) instead of rasterio’s bounds (left, bottom, right, top)

  • source (array or dataset object opened in 'r' mode) – If array, data in the order rows, columns and optionally bands. If array is band order (bands in the first dimension), use arr[0]

  • transform (Affine, required if source is array) – Defines the affine transform if source is an array


left, right, bottom, top

Return type

tuple of float


Returns the source array reshaped into the order expected by image processing and visualization software (matplotlib, scikit-image, etc) by swapping the axes order from (bands, rows, columns) to (rows, columns, bands)


arr (array-like of shape (bands, rows, columns)) – image to reshape


Returns the array in a raster order by swapping the axes order from (rows, columns, bands) to (bands, rows, columns)


arr (array-like in the image form of (rows, columns, bands)) – image to reshape

rasterio.plot.show(source, with_bounds=True, contour=False, contour_label_kws=None, ax=None, title=None, transform=None, adjust='linear', **kwargs)

Display a raster or raster band using matplotlib.

  • source (array or dataset object opened in 'r' mode or Band or tuple(dataset, bidx)) – If Band or tuple (dataset, bidx), display the selected band. If raster dataset display the rgb image as defined in the colorinterp metadata, or default to first band.

  • with_bounds (bool (opt)) – Whether to change the image extent to the spatial bounds of the image, rather than pixel coordinates. Only works when source is (raster dataset, bidx) or raster dataset.

  • contour (bool (opt)) – Whether to plot the raster data as contours

  • contour_label_kws (dictionary (opt)) – Keyword arguments for labeling the contours, empty dictionary for no labels.

  • ax (matplotlib axes (opt)) – Axes to plot on, otherwise uses current axes.

  • title (str, optional) – Title for the figure.

  • transform (Affine, optional) – Defines the affine transform if source is an array

  • adjust ('linear' | None) – If the plotted data is an RGB image, adjust the values of each band so that they fall between 0 and 1 before plotting. If ‘linear’, values will be adjusted by the min / max of each band. If None, no adjustment will be applied.

  • **kwargs (key, value pairings optional) – These will be passed to the matplotlib imshow or contour method depending on contour argument. See full lists at: http://matplotlib.org/api/axes_api.html?highlight=imshow#matplotlib.axes.Axes.imshow or http://matplotlib.org/api/axes_api.html?highlight=imshow#matplotlib.axes.Axes.contour


ax – Axes with plot.

Return type

matplotlib Axes

rasterio.plot.show_hist(source, bins=10, masked=True, title='Histogram', ax=None, label=None, **kwargs)

Easily display a histogram with matplotlib.

  • source (array or dataset object opened in 'r' mode or Band or tuple(dataset, bidx)) – Input data to display. The first three arrays in multi-dimensional arrays are plotted as red, green, and blue.

  • bins (int, optional) – Compute histogram across N bins.

  • masked (bool, optional) – When working with a rasterio.Band() object, specifies if the data should be masked on read.

  • title (str, optional) – Title for the figure.

  • ax (matplotlib axes (opt)) – The raster will be added to this axes if passed.

  • label (matplotlib labels (opt)) – If passed, matplotlib will use this label list. Otherwise, a default label list will be automatically created

  • **kwargs (optional keyword arguments) – These will be passed to the matplotlib hist method. See full list at: http://matplotlib.org/api/axes_api.html?highlight=imshow#matplotlib.axes.Axes.hist