Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Choropleth Map

Signature

sp.build_choropleth(
    title: str,
    labels: list[str],
    values: list[float],
    *,
    iso_codes: list[str] | None = None,
    color_low: int = 0,
    color_high: int = 0,
    palette: list[int] | None = None,
    width: int = 1000,
    height: int = 600,
    background: str | None = None,
    hover_json: str | None = None,
    show_legend: bool = True,
    null_color: int = 0xdddddd,
) -> Chart

Aliases: sp.choropleth


Description

Choropleth (filled map) — country or region polygons colored by a scalar value.

Countries without data receive the null_color. Provide iso_codes (ISO-3166 alpha-3) to match countries automatically.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
labelslist[str]requiredCountry
valueslist[float]requiredValues to color by
iso_codeslist[str] | NoneNoneISO-3166 alpha-3 codes
color_lowintautoLow value color
color_highintautoHigh value color
null_colorint0xddddddColor for countries with no data
widthint1000Canvas width
heightint600Canvas height
show_legendboolTrueShow color scale legend
hover_jsonstr | NoneNoneCustom hover JSON

Returns

Chart


Examples

Unemployment rate choropleth

import seraplot as sp
chart = sp.build_choropleth(
    "Unemployment Rate by Country",
    labels=["FRA", "DEU", "ESP", "ITA", "PRT"],
    values=[7.1, 3.0, 11.8, 6.7, 6.2],
)
const sp = require('seraplot');
const chart = sp.build_choropleth("Unemployment Rate by Country",
["FRA", "DEU", "ESP", "ITA", "PRT"],
{
    values: [7.1, 3.0, 11.8, 6.7, 6.2]
})
import * as sp from 'seraplot';
const chart = sp.build_choropleth("Unemployment Rate by Country",
["FRA", "DEU", "ESP", "ITA", "PRT"],
{
    values: [7.1, 3.0, 11.8, 6.7, 6.2]
})
▶ Live Preview

See also

Signature

sp.build_choropleth(
    title: str,
    labels: list[str],
    values: list[float],
    *,
    iso_codes: list[str] | None = None,
    color_low: int = 0,
    color_high: int = 0,
    palette: list[int] | None = None,
    width: int = 1000,
    height: int = 600,
    background: str | None = None,
    hover_json: str | None = None,
    show_legend: bool = True,
    null_color: int = 0xdddddd,
) -> Chart

Aliases: sp.choropleth


Description

Carte choro-plèthe — polygones de pays/régions colorés par une valeur scalaire. Les pays sans données reçoivent la null_color. Fournissez des iso_codes (ISO-3166 alpha-3) pour associer les pays automatiquement.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
labelslist[str]requisPays
valueslist[float]requisValeurs pour la colorisation
iso_codeslist[str] | NoneNoneCodes ISO-3166 alpha-3
color_lowintautoCouleur pour les valeurs basses
color_highintautoCouleur pour les valeurs hautes
null_colorint0xddddddCouleur des pays sans données
widthint1000Largeur du canvas
heightint600Hauteur du canvas
show_legendboolTrueAfficher l'échelle de couleur
hover_jsonstr | NoneNoneJSON d'infobulle personnalisée

Retourne

Chart


Exemples

import seraplot as sp

chart = sp.build_choropleth(
    "Taux de chômage par pays",
    labels=["FRA", "DEU", "ESP", "ITA", "PRT"],
    values=[7.1, 3.0, 11.8, 6.7, 6.2],
)

Voir aussi