map(
data,
variable,
year=None,
scale=None,
title=None,
simplify='auto',
ref=None,
*,
scheme=None,
k=5,
bins=None,
change=False,
**kwargs,
)
An interactive choropleth map (Plotly) of one variable: in one year, in several years side by side, or its change between two years; on a continuous colour scale or in classes.
Parameters
| data |
|
A dataset id, or a panel with geo_id (with or without geometry), e.g. from geo.load, geo.change or geo.aggregate |
required |
| variable |
str |
The column to colour by |
required |
| year |
|
The year to map (default: the last year with data), or a list of years ([2012, 2024]): one map per year, side by side, in the same classes or on the same colour range, computed over all the years shown, so the maps can be compared. Ignored for tables without a year column |
None |
| scale |
str | None |
The units’ scale (default: inferred from geo_id) |
None |
| title |
str | None |
The figure title (default: the variable’s label and the year) |
None |
| simplify |
float | str | None |
How much to simplify the drawn boundaries, which keeps the figure light. "auto" (the default) removes detail smaller than about 1/600 of the map’s extent, invisible at the scale of the whole map; a number is a tolerance in degrees (0.005 is about 500 m), for maps you will zoom into; None draws the boundaries in full detail. Neighbouring units keep fitting each other |
'auto' |
| scheme |
str | None |
Draw classes instead of a continuous scale, one colour per class with its range in the legend: "fisher_jenks" (natural breaks: similar values together), "quantiles" (the same number of units in each class) or "equal_interval" (classes of the same width) |
None |
| k |
int |
The number of classes of a scheme |
5 |
| bins |
|
Explicit class limits in increasing order ([20, 40, 60]), instead of a scheme; values below the first or above the last limit get a class of their own |
None |
| change |
bool |
Map the change of the variable (last minus first year, as geo.change computes it) between the first and last year with data, or between the two years given in year, on a diverging scale centred at zero. With a scheme, the classes split at zero: they are computed within the falls and within the rises |
False |
| **kwargs |
|
For the continuous map of one year, passed to plotly.express.choropleth_map (e.g. color_continuous_scale="Viridis", range_color=(0, 100)). With classes, several years or change, the options are color_continuous_scale, range_color, map_style, opacity, center, zoom, height and width |
{} |
Returns
|
plotly.graph_objects.Figure |
A plotly.graph_objects.Figure; it displays in a notebook, and .show() displays it from a script or a cell that does more afterwards. A map in classes keeps their limits in fig.layout.meta["bins"]. |
Example
!pip install -q geo4bolivia
import geo4bolivia as geo
# Multidimensional poverty in both periods, in common natural-break classes
geo.map("sdg01", "sdg1_2_mpi", year=[2012, 2024], scheme="fisher_jenks")