import altair as alt
import attaviz
import pandas as pd
attaviz.enable()
source = pd.DataFrame(
{
"site": ["Crookston", "Duluth", "Grand Rapids", "Morris", "University Farm"],
"yield": [35.1, 33.0, 24.9, 35.4, 32.7],
}
)
alt.Chart(source, title="Barley yield by site").mark_bar().encode(
x="yield:Q",
y="site:N",
)Quick start
Attaviz gives you two ways to make charts in the WBG style. Enable the theme and every Altair chart you write uses it, or use a chart template and it makes common editorial choices for you.
Style any Altair chart
Run attaviz.enable() once. Every Altair chart after that call uses WBG fonts, colors, and spacing. You do not need to change your chart code.
Use a chart template
A chart template builds a complete chart from summarized data. Pass your data to a template such as attaviz.bar().
attaviz.bar(
source,
category="site",
value="yield",
title="Barley yield by site",
subtitle="Mean yield across varieties and years",
)Templates handle recurring editorial choices such as sorting, labels, tooltips, highlighting, number formatting, and responsive width. They return ordinary Altair charts, so further customization remains available.
chart = attaviz.bar(
source,
category="site",
value="yield",
highlight="Morris",
title="Morris has the highest yield in this example",
subtitle="Illustrative mean yield, bushels per acre",
width=600,
)
attaviz.frame(
chart,
description="Horizontal bars comparing illustrative barley yields at five sites; Morris is highest.",
source="Illustrative example data",
note="Values are provided for demonstration.",
byline="Attaviz",
)Set title and subtitle on the template, then apply frame() after adding hover, annotations, or reference marks. The frame adds the footer and a required accessibility description; the description is not a visible subtitle. Prefixes such as “Source:” and “Note:” are added automatically. See the complete frame example for source links and sizing.
Create a styled table
Install the optional table support:
uv add "attaviz[tables]"
# or
pip install "attaviz[tables]"Use the same DataFrame to show exact values alongside a chart:
(
attaviz.table(
source,
title="Barley yield by site",
subtitle="Mean yield across varieties and years",
source="Source: quickstart example data.",
)
.cols_label(**{"site": "Site", "yield": "Yield (bushels/acre)"})
.fmt_number(columns="yield", decimals=1)
)| Barley yield by site | |
| Mean yield across varieties and years | |
| Site | Yield (bushels/acre) |
|---|---|
| Crookston | 35.1 |
| Duluth | 33.0 |
| Grand Rapids | 24.9 |
| Morris | 35.4 |
| University Farm | 32.7 |
| Source: quickstart example data. | |
table() returns a native Great Tables object, so you can chain its formatting and customization methods. Missing values display as N/A; numbers retain their precision until you format them. Tables work without calling attaviz.enable(). Follow the table guide for counts, percentages, currency, grouped headings, footnotes, and export.
Size variants
Three typography/spacing presets are available. Pick the one that matches the intended display width.
attaviz.enable(size="small") # charts under ~400px wide
attaviz.enable(size="medium") # 400–700px (default)
attaviz.enable(size="large") # wider than 700pxPer-chart sizing
To size a single chart without switching the global theme:
chart = attaviz.bar(source, category="site", value="yield")
chart = attaviz.configure_size(chart, width=600, aspect_ratio="16:9")
chartFor a framed chart, set width and height on the template itself.
Use number and date formats for axes, tooltips, and Python labels.
Next, read the chart template reference, map reference, table reference, or browse the gallery.