onstove.OnStove.to_image#
- OnStove.to_image(variable: str, name: 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 = {'size': 12, 'title': {'size': 12, 'weight': 'bold'}}, stats: bool = False, stats_kwargs: dict | None = None, scale_bar: dict | None = None, north_arrow: dict | None = None, figsize: tuple[float, float] = (6.4, 4.8), rasterized: bool = True, dpi: float = 150)[source]#
Saves a map from a desired column
variable
from thegdf
into an image file.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.- name: str
The map will be saved with that name and extension file in the:attr:output_directory as
name.pdf
,name.png
,name.svg
, etc.- 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. .. code-block:
:caption: ``stats_kwargs`` default arguments {'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 won’t be displayed.
dict(size=30, location=(0.92, 0.92), linewidth=0.5)
Note
See
onstove.north_arrow()
for more details- 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.