Skip to content
dysonsphere

Multilabels

add_multilabel() attaches an annotation table below a chart - +/- rows, symbols, or plain text aligned to each x category, with optional sample-size and category-label rows and grouped spans.

import dysonsphere as ds
from vega_datasets import data
ds.theme()
cars = ds.ensure_polars(data.cars()).drop_nulls(["Miles_per_Gallon"])
origins = ["USA", "Europe", "Japan"]
strip = ds.mark_strip(cars, "Origin", "Miles_per_Gallon", origins, yTitle="Miles per gallon")
# A multilabel table below the chart: +/- rows aligned to each category.
chart = ds.add_multilabel(
strip,
groups={"Domestic": [True, False, False], "High volume": [True, True, False]},
categories=origins,
)

showSampleSize=True injects a per-category count row, and categoryLabel=True renders the category names as an angled row of the table:

import dysonsphere as ds
from vega_datasets import data
ds.theme()
cars = ds.ensure_polars(data.cars()).drop_nulls(["Miles_per_Gallon"])
origins = ["USA", "Europe", "Japan"]
strip = ds.mark_strip(cars, "Origin", "Miles_per_Gallon", origins, yTitle="Miles per gallon")
# Add per-category sample sizes and the category labels as annotation rows.
chart = ds.add_multilabel(
strip,
categories=origins,
showSampleSize=True, df=cars, xCol="Origin",
categoryLabel=True,
)

Use style="symbol" for filled/open dots, and span= to bracket groups of categories under a shared label:

import dysonsphere as ds
from vega_datasets import data
ds.theme()
cars = ds.ensure_polars(data.cars()).drop_nulls(["Miles_per_Gallon"])
origins = ["USA", "Europe", "Japan"]
strip = ds.mark_strip(cars, "Origin", "Miles_per_Gallon", origins, yTitle="Miles per gallon")
# Symbol-style rows (filled / open dots) with grouped spans bracketing categories.
chart = ds.add_multilabel(
strip,
groups={"Turbocharged": [True, False, True], "Fuel injected": [True, True, False]},
categories=origins,
style="symbol",
span=[{"Domestic": ["USA"]}, {"Imported": ["Europe", "Japan"]}],
spanBracketStyle="bracket",
)