onstove.OnStove.plot#
- OnStove.plot(variable: str, metric='mean', labels: dict[str, str] | None = None, cmap: dict[str, str] | str = 'viridis', cumulative_count: tuple[float, float] | None = None, quantiles: tuple[float] | None = None, nodata: float | int = nan, admin_layer: GeoDataFrame | VectorLayer | None = None, title: str | None = None, legend: bool = True, legend_title: str = '', legend_cols: int = 1, legend_position: tuple[float, float] = (1.02, 0.6), legend_prop: dict | None = None, stats: bool = False, stats_kwargs: dict | None = None, scale_bar: dict | None = None, north_arrow: dict | None = None, ax: Axes | None = None, figsize: tuple[float, float] = (6.4, 4.8), rasterized: bool = True, dpi: float = 150, save_as: str | None = None, save_style: bool = False, style_classes: int = 5) Axes [source]#
Plots a map from a desired column
variable
from thegdf
.The map can be for categorical or continuous data. If categorical, a legend will be created with the colors of the categories. If continuous, a color bar will be created with the range of the data. For continuous data a
metric
parameter can be passed indicating the desired statistic to be visualized. Moreover, continuous data can be presented usingcumulative_count
orquantiles
.- Parameters:
- variable: str
The column name from the
gdf
to plot.- metric: str, default ‘mean’
Metric to use to aggregate data. It is only used for continuous data. For available metrics see
create_layer()
.- labels: dictionary of str key-value pairs, optional
Dictionary with the keys-value pairs to use for the data categories. It is only used for categorical data— see
create_layer()
.- cmap: dictionary of str key-value pairs or str, default ‘viridis’
Dictionary with the colors to use for each data category if the data is categorical—see
create_layer()
. If the data is continuous, then a name of a color scale accepted by matplotlib should be passed.- 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.
See also
- 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.See also
- nodata: float or int, default ```np.nan`
Defines nodata values to be ignored when plotting.
- admin_layer: gpd.GeoDataFrame or VectorLayer, optional
The administrative boundaries to plot as background. If no
admin_layer
is provided then the :attr:mask_layer
will be used if available, if not then no boundaries will be plotted.- title: str, optional
The title of the plot.
- 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}
.- stats: bool, default False
Whether to display the statistics of the analysis in the map.
- stats_kwargs: dictionary, optional
Dictionary of arguments to control the position and style of the statistics box.
{'extra_stats': None, 'stats_position': (1.02, 0.9), 'pad': 0, 'sep': 6, 'fontsize': 10, 'fontcolor': 'black', 'fontweight': 'normal', 'box_props': dict(boxstyle='round', facecolor='#f1f1f1ff', edgecolor='lightgray')}
{'extra_stats': dict('StatA': value), 'fontsize': 10, 'stats_position': (1, 0.9), 'pad': 2, 'sep': 0, 'fontcolor': 'black', 'fontweight': 'normal', 'box_props': dict(facecolor='lightyellow', edgecolor='black', alpha=1, boxstyle="sawtooth")}
- scale_bar: dict, optional
Dictionary with the parameters needed to create a
ScaleBar
. If not defined, no scale bar will be displayed.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 wont be displayed.
dict(size=30, location=(0.92, 0.92), linewidth=0.5)
Note
See
onstove.north_arrow()
for more details- ax: matplotlib.axes.Axes, optional
A matplotlib axes instance can be passed in order to overlay layers in the same axes.
- figsize: tuple of floats, default (6.4, 4.8)
The size of the figure in inches.
- 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.
- dpi: int, default 150
The resolution of the figure in dots per inch.
- save_as: str, optional
If a string is passed, then the map will be saved with that name and extension file in the:attr:output_directory as
name.pdf
,name.png
,name.svg
, etc.- save_style: bool, default False
Whether to save the style of the plot as a
.sld
file—seeonstove.RasterLayer.save_style()
.- style_classes: int, default 5
number of classes to include in the
.sld
style.
- Returns:
- matplotlib.axes.Axes
The axes of the figure.
Examples
>>> africa = OnStove('results.pkl') ... >>> cmap = {'Biomass ICS (ND)': '#6F4070', ... 'LPG': '#66C5CC', ... 'Biomass': '#FFB6C1', ... 'Biomass ICS (FD)': '#af04b3', ... 'Pellets ICS (FD)': '#ef02f5', ... 'Charcoal': '#364135', ... 'Charcoal ICS': '#d4bdc5', ... 'Biogas': '#73AF48', ... 'Biogas and Biomass ICS (ND)': '#F6029E', ... 'Biogas and Biomass ICS (FD)': '#F6029E', ... 'Biogas and Pellets ICS (FD)': '#F6029E', ... 'Biogas and LPG': '#0F8554', ... 'Biogas and Biomass': '#266AA6', ... 'Biogas and Charcoal': '#3B05DF', ... 'Biogas and Charcoal ICS': '#3B59DF', ... 'Electricity': '#CC503E', ... 'Electricity and Biomass ICS (ND)': '#B497E7', ... 'Electricity and Biomass ICS (FD)': '#B497E7', ... 'Electricity and Pellets ICS (FD)': '#B497E7', ... 'Electricity and LPG': '#E17C05', ... 'Electricity and Biomass': '#FFC107', ... 'Electricity and Charcoal ICS': '#660000', ... 'Electricity and Biogas': '#f97b72', ... 'Electricity and Charcoal': '#FF0000'} ... >>> labels = {'Biogas and Electricity': 'Electricity and Biogas', ... 'Collected Traditional Biomass': 'Biomass', ... 'Collected Improved Biomass': 'Biomass ICS (ND)', ... 'Traditional Charcoal': 'Charcoal', ... 'Biomass Forced Draft': 'Biomass ICS (FD)', ... 'Pellets Forced Draft': 'Pellets ICS (FD)'} ... >>> scale_bar_prop = dict(size=1000000, style='double', textprops=dict(size=8), ... linekw=dict(lw=1, color='black'), extent=0.01) >>> north_arow_prop = dict(size=30, location=(0.92, 0.92), linewidth=0.5) ... >>> africa.plot('max_benefit_tech', labels=labels, cmap=cmap, ... stats=True, ... legend=True, legend_position=(0.03, 0.47), ... legend_title='Maximum benefit cooking technology', ... legend_prop={'title': {'size': 10, 'weight': 'bold'}, 'size': 10}, ... scale_bar=scale_bar_prop, north_arrow=north_arow_prop, ... figsize=(16, 9), dpi=300, rasterized=True)