Horizontal Bar Chart
Signature
sp.build_hbar(
title: str,
labels: list[str],
values: list[float],
*,
color_hex: int = 0,
show_text: bool = True,
color_groups: list[str] | None = None,
width: int = 900,
height: int = 500,
x_label: str = "",
y_label: str = "",
gridlines: bool = False,
sort_order: str = "none",
hover_json: str = "",
legend_position: str = "right",
palette: list[int] | None = None,
background: str | None = None,
no_x_axis: bool = False,
no_y_axis: bool = False,
) -> Chart
Aliases: sp.hbar, sp.barh, sp.horizontal_bar
Description
Horizontal bar chart. Best for long category labels or ranking comparisons.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Chart title |
labels | list[str] | required | Category labels |
values | list[float] | required | Bar values |
show_text | bool | True | Show values on bars (default True for hbar) |
sort_order | str | "none" | "asc", "desc", "none" |
color_groups | list[str] | None | None | Group names for color mapping |
palette | list[int] | None | None | Custom hex color palette |
background | str | None | None | Background CSS color |
width | int | 900 | Width in pixels |
height | int | 500 | Height in pixels |
Returns
Chart
Examples
Top 10 ranking
import seraplot as sp
chart = sp.build_hbar(
"Top Countries by GDP",
labels=["USA", "China", "Germany", "Japan", "India", "UK", "France", "Brazil", "Canada", "Korea"],
values=[25.0, 18.0, 4.1, 4.2, 3.7, 3.1, 2.9, 2.1, 2.0, 1.7],
sort_order="desc",
x_label="GDP (trillion USD)",
show_text=True,
width=900,
height=460,
)const sp = require('seraplot');
const chart = sp.build_hbar("Top Countries by GDP",
["USA", "China", "Germany", "Japan", "India", "UK", "France", "Brazil", "Canada", "Korea"],
{
values: [25.0, 18.0, 4.1, 4.2, 3.7, 3.1, 2.9, 2.1, 2.0, 1.7],
sort_order: "desc",
x_label: "GDP (trillion USD)",
show_text: true,
width: 900,
height: 460
})import * as sp from 'seraplot';
const chart = sp.build_hbar("Top Countries by GDP",
["USA", "China", "Germany", "Japan", "India", "UK", "France", "Brazil", "Canada", "Korea"],
{
values: [25.0, 18.0, 4.1, 4.2, 3.7, 3.1, 2.9, 2.1, 2.0, 1.7],
sort_order: "desc",
x_label: "GDP (trillion USD)",
show_text: true,
width: 900,
height: 460
})▶ Live Preview
See also
Signature
sp.build_hbar(
title: str,
labels: list[str],
values: list[float],
*,
color_hex: int = 0,
show_text: bool = True,
color_groups: list[str] | None = None,
width: int = 900,
height: int = 500,
x_label: str = "",
y_label: str = "",
gridlines: bool = False,
sort_order: str = "none",
hover_json: str = "",
legend_position: str = "right",
palette: list[int] | None = None,
background: str | None = None,
no_x_axis: bool = False,
no_y_axis: bool = False,
) -> Chart
Aliases: sp.hbar, sp.barh, sp.horizontal_bar
Description
Graphique en barres horizontales. Particulièrement adapté aux longues étiquettes de catégories ou aux classements.
Paramètres
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
title | str | requis | Titre du graphique |
labels | list[str] | requis | Étiquettes des catégories |
values | list[float] | requis | Valeurs des barres |
show_text | bool | True | Afficher les valeurs sur les barres |
sort_order | str | "none" | "asc", "desc" ou "none" |
color_groups | list[str] | None | None | Noms de groupe pour la coloration |
palette | list[int] | None | None | Palette de couleurs hex |
background | str | None | None | Couleur de fond CSS |
width | int | 900 | Largeur en pixels |
height | int | 500 | Hauteur en pixels |
Retourne
Chart
Exemples
Top 10 classement
import seraplot as sp
chart = sp.build_hbar(
"Top pays par PIB",
labels=["USA", "Chine", "Allemagne", "Japon", "Inde", "UK", "France", "Brésil", "Canada", "Corée"],
values=[25.0, 18.0, 4.1, 4.2, 3.7, 3.1, 2.9, 2.1, 2.0, 1.7],
sort_order="desc",
x_label="PIB (billions USD)",
show_text=True,
)
Voir aussi
- Graphique en barres —
sp.build_bar_chart() - Lollipop —
sp.build_lollipop_chart()