brand¶
Every organisation-specific value — colors, palettes, font stack and which
color is used for what — lives in a Brand. The theme builders only read from
a Brand, so supporting another organisation means defining a new one; no
theme code changes. The built-in Charité brand is defined in
charite_plot/brands/charite.py and is the default everywhere.
from charite_plot import Brand, Roles, register_brand
from charite_plot import mpl_themes, altair_themes, make_palette
register_brand(
Brand(
name="demo",
display_name="Demo Organisation",
colors={"red": "#aa0000", "blue": "#0000aa"},
palettes={"main": ["#aa0000", "#0000aa"]},
roles=Roles(
primary="#aa0000",
text="#333333",
axis="#000000",
grid="#dddddd",
diverging=("#0000aa", "#ffffff", "#aa0000"),
sequential=("#ffffff", "#aa0000"),
),
font_stack=["Source Sans 3", "DejaVu Sans", "sans-serif"],
default_palette="main",
)
)
mpl_themes.enable(brand="demo")
altair_themes.enable(brand="demo") # registered as Altair theme "demo"
make_palette("main", 5, brand="demo")
A Brand instance can also be passed directly (enable(brand=my_brand))
without registering it.
tint(color, percent)
¶
Return color at percent % strength, i.e. mixed with white (100 is the color itself).
This is how print-style tint scales ("Tonwerte") are defined, e.g. tint("#003754", 20) == "#ccd7dd".
Brand
dataclass
¶
A corporate identity: colors, palettes, fonts and color roles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Short registry key, e.g. |
required |
display_name
|
str
|
Human-readable name, e.g. |
required |
colors
|
Mapping[str, str]
|
All named brand colors (lowercase name → hex). |
required |
palettes
|
Mapping[str, Sequence[str]]
|
Named categorical palettes (name → list of hex colors). |
required |
roles
|
Roles
|
Color roles used by the theme builders. |
required |
font_stack
|
Sequence[str]
|
Preferred fonts in fallback order, ending in a generic family. |
required |
default_palette
|
str
|
Palette used when a theme is built without an explicit |
'primary'
|
palette(name_or_colors=None)
¶
Resolve a palette name (or pass through a color list) to a list of hex colors.
None returns the brand's default_palette.
Roles
dataclass
¶
Which brand color is used for which part of a chart.
register_brand(brand)
¶
Add brand to the registry (replacing any brand with the same name).
get_brand(brand=DEFAULT_BRAND)
¶
Return the registered brand called brand, or brand itself if it is a Brand.
BRANDS = {CHARITE.name: CHARITE, BIH.name: BIH}
module-attribute
¶
Registered brands by name. Built in: "charite" and "bih"; add more with register_brand.
DEFAULT_BRAND = CHARITE.name
module-attribute
¶
Brand used when no brand is given: "charite".
Built-in brands¶
| Brand | Object | Default palette |
|---|---|---|
"charite" |
charite_plot.CHARITE |
primary |
"bih" |
charite_plot.BIH |
accents |