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

Bubble Chart

Signature

sp.build_bubble(
    title: str,
    x_values: list[float],
    y_values: list[float],
    sizes: list[float],
    *,
    labels: list[str] | None = None,
    color_groups: list[str] | None = None,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    gridlines: bool = True,
    background: str | None = None,
    hover_json: str | None = None,
) -> Chart

Aliases: sp.bubble


Description

Bubble chart: scatter plot where each point's area encodes a third dimension (sizes).


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
x_valueslist[float]requiredX-axis positions
y_valueslist[float]requiredY-axis positions
sizeslist[float]requiredValues that drive bubble radius
labelslist[str] | NoneNonePer-bubble text labels
color_groupslist[str] | NoneNoneGroup names for coloring
color_hexint0x6366F1Default bubble color
palettelist[int] | NoneNoneCustom palette per group
widthint900Canvas width
heightint480Canvas height
x_labelstr""X-axis label
y_labelstr""Y-axis label
gridlinesboolTrueGridlines
hover_jsonstr | NoneNoneCustom hover JSON

Returns

Chart


Examples

Gapminder-style chart

import seraplot as sp
countries = ["USA", "China", "Germany", "India", "Brazil"]
gdp       = [65000, 12500, 48000, 2100, 8800]
life_exp  = [78.5, 77.1, 81.3, 69.7, 75.2]
population= [331, 1412, 83, 1380, 212]
chart = sp.build_bubble(
    "GDP vs Life Expectancy (2023)",
    x_values=gdp,
    y_values=life_exp,
    sizes=[p / 10 for p in population],
    categories=countries,
    x_label="GDP per capita ($)",
    y_label="Life expectancy (years)",
)
const sp = require('seraplot');
const countries = ["USA", "China", "Germany", "India", "Brazil"]
const gdp       = [65000, 12500, 48000, 2100, 8800]
const life_exp  = [78.5, 77.1, 81.3, 69.7, 75.2]
const population= [331, 1412, 83, 1380, 212]
const chart = sp.build_bubble("GDP vs Life Expectancy (2023)",
gdp,
life_exp,
{
    sizes: [p / 10 for p in population],
    categories: countries,
    x_label: "GDP per capita ($)",
    y_label: "Life expectancy (years)"
})
import * as sp from 'seraplot';
const countries: string[] = ["USA", "China", "Germany", "India", "Brazil"]
const gdp: number[] = [65000, 12500, 48000, 2100, 8800]
const life_exp: number[] = [78.5, 77.1, 81.3, 69.7, 75.2]
const population= [331, 1412, 83, 1380, 212]
const chart = sp.build_bubble("GDP vs Life Expectancy (2023)",
gdp,
life_exp,
{
    sizes: [p / 10 for p in population],
    categories: countries,
    x_label: "GDP per capita ($)",
    y_label: "Life expectancy (years)"
})
▶ Live Preview

See also

Signature

sp.build_bubble(
    title: str,
    x_values: list[float],
    y_values: list[float],
    sizes: list[float],
    *,
    labels: list[str] | None = None,
    color_groups: list[str] | None = None,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    gridlines: bool = True,
    background: str | None = None,
    hover_json: str | None = None,
) -> Chart

Aliases: sp.bubble


Description

Graphique à bulles : nuage de points où la surface de chaque point encode une troisième dimension (sizes).


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
x_valueslist[float]requisPositions sur l'axe X
y_valueslist[float]requisPositions sur l'axe Y
sizeslist[float]requisValeurs déterminant le rayon des bulles
labelslist[str] | NoneNoneÉtiquettes textuelles par bulle
color_groupslist[str] | NoneNoneNoms de groupe pour la coloration
color_hexint0x6366F1Couleur par défaut des bulles
palettelist[int] | NoneNonePalette personnalisée par groupe
widthint900Largeur du canvas
heightint480Hauteur du canvas
x_labelstr""Étiquette de l'axe X
y_labelstr""Étiquette de l'axe Y
gridlinesboolTrueLignes de grille
hover_jsonstr | NoneNoneJSON d'infobulle personnalisée

Retourne

Chart


Exemples

Style Gapminder

import seraplot as sp

pays = ["USA", "Chine", "Allemagne", "Inde", "Brésil"]
pib       = [65000, 12500, 48000, 2100, 8800]
esp_vie   = [78.5, 77.1, 81.3, 69.7, 75.2]
population= [331, 1412, 83, 1380, 212]

chart = sp.build_bubble(
    "PIB vs Espérance de vie (2023)",
    x_values=pib,
    y_values=esp_vie,
    sizes=[p / 10 for p in population],
    color_groups=pays,
    x_label="PIB par habitant ($)",
    y_label="Espérance de vie (ans)",
)

Voir aussi