onstove.RasterLayer.plot#

RasterLayer.plot(cmap: dict[str, str] | str = 'viridis', ticks: list = None, tick_labels: list = None, cumulative_count: tuple[float, float] | None = None, quantiles: tuple[float] | None = None, categories: dict | None = None, admin_layer: GeoDataFrame | VectorLayer | None = None, title: str | None = None, ax: Axes | None = None, legend: bool = True, legend_title: str = '', legend_cols: int = 1, legend_position: tuple[float, float] = (1.02, 0.7), legend_prop: dict | None = None, rasterized: bool = True, colorbar: bool = True, colorbar_kwargs: dict | None = None, figsize: tuple[float, float] = (6.4, 4.8), scale_bar: dict | None = None, north_arrow: dict | None = None, alpha: float = 1)[source]#

Plots a map of the raster data.

The map can be for categorical or continuous data. If categorical, you need to pass a categories dictionary defining the categories of the data values. In such case, a legend will be created with the colors of the categories following the colors provided in cmap, otherwise a default colormap will be used. If continuous, a color bar will be created with the range of the data. Continuous data can also be presented using cumulative_count or quantiles.

Parameters:
cmap: dictionary of key-value pairs or str, default ‘viridis’

Dictionary with the colors to use for each data category if the data is categorical. If the data is continuous, then a name of a color scale accepted by matplotlib should be passed (e.g. viridis, magma, Spectral, etc.).

cmap examples for categorical data#
cmap={0: 'lightblue', 1: 'Brown',
      2: 'Yellow', 3: 'Gray',
      4: 'aquamarine', 5: 'Green',
      6: 'Black'}
cmap='tab10' # to use the tab10 pallet
ticks: list, optional

A list of values where ticks should be defined in the colorbar. Applicable only for continuous data.

tick_labels: list, optional

List of labels to show in every tick. The dimension and order should match the tick ones.

cumulative_count: array-like of float, optional

List of lower and upper limits to consider for the cumulative count. If defined the map will be displayed with the cumulative count representation of the data.

quantiles: array-like of float, optional

Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive (quantiles=(0.25, 0.5, 0.75, 1)). If defined the map will be displayed with the quantiles representation of the data.

categories: dictionary, optional

Dictionary containing as keys the raster values representing the categories and as values the names of the raster of each category. Applicable only for categorical data.

categories examples for categorical data#
categories={'Electricity': 0., 'LPG': 1,
            'Biogas': 2, 'Biomass': 3,
            'Charcoal': 4, 'ICS': 5,
            'Mini Grids': 6}
admin_layer: gpd.GeoDataFrame or VectorLayer, optional

The administrative boundaries to plot as background.

title: str, optional

The title of the plot.

ax: matplotlib.axes.Axes, optional

A matplotlib axes instance can be passed in order to overlay layers in the same axes.

legend: bool, default False

Whether to display a legend—only applicable for categorical data.

legend_title: str, default ‘’

Title of the legend.

legend_cols: int, default 1

Number of columns to divide the rows of the legend.

legend_position: array-like of float, default (1.05, 1)

Position of the upper-left corner of the legend measured in fraction of x and y axis.

legend_prop: dict

Dictionary with the font properties of the legend. It can contain any property accepted by the prop parameter from matplotlib.pyplot.legend. It defaults to {'title': {'size': 12, 'weight': 'bold'}, 'size': 12, 'frameon': False}.

rasterized: bool, default True

Whether to rasterize the output.It converts vector graphics into a raster image (pixels). It can speed up rendering and produce smaller files for large data sets—see more at Rasterization for vector graphics.

colorbar: bool, default False

Indicates whether to display the colorbar or not. Applicable only for continuous data.

colorbar_kwargs: dict, optional

Arguments used to position and style the colorbar. For example

colorbar_kwargs example#
 dict(title_prop=dict(label='Distance (meters)',
                      loc='center', labelpad=10,
                      fontweight='normal'),
      width=0.05, height=0.8, x=1.04, y=0.1)
figsize: tuple of floats, default (6.4, 4.8)

The size of the figure in inches.

scale_bar: dict, optional

Dictionary with the parameters needed to create a ScaleBar. If not defined, no scale bar will be displayed.

Scale bar dictionary example#
dict(size=1000000, style='double',
     textprops=dict(size=8),
     location=(1, 0),
     linekw=dict(lw=1, color='black'),
     extent=0.01)

Note

See onstove.scale_bar() for more details

north_arrow: dict, optional

Dictionary with the parameters needed to create a north arrow icon in the map. If not defined, the north icon won’t be displayed.

North arrow dictionary example#
north_arrow=dict(size=30,
                 location=(0.92, 0.92),
                 linewidth=0.5)

Note

See onstove.north_arrow() for more details

alpha: float, default 1

Value used to set the transparency of the plot. It should be a value between 0 and 1, being 1 no transparency and 0 complete transparency.

Returns:
matplotlib.axes.Axes

The axes of the figure.