charite-plot 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {charite_plot-0.2.0 → charite_plot-0.3.0}/CHANGELOG.md +16 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/CITATION.cff +1 -1
- {charite_plot-0.2.0 → charite_plot-0.3.0}/PKG-INFO +20 -11
- {charite_plot-0.2.0 → charite_plot-0.3.0}/README.md +19 -10
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/__init__.py +17 -8
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/_theme_common.py +2 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/altair_themes.py +41 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/fonts.py +2 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/mpl_themes.py +42 -15
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/palettes.py +2 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/api/altair_themes.md +1 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/api/mpl_themes.md +1 -1
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/citing.md +1 -1
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/index.md +5 -5
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/installation.md +2 -2
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/matplotlib.md +14 -13
- {charite_plot-0.2.0 → charite_plot-0.3.0}/examples/mpl_showcase.py +2 -2
- {charite_plot-0.2.0 → charite_plot-0.3.0}/examples/palette_preview.py +2 -2
- {charite_plot-0.2.0 → charite_plot-0.3.0}/examples/poly_showcase.py +2 -2
- {charite_plot-0.2.0 → charite_plot-0.3.0}/.github/workflows/ci.yml +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/.gitignore +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/LICENSE.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/colors.py +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/charite_plot/py.typed +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/altair.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/api/colors.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/api/fonts.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/api/palettes.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/assets/palette_preview.png +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/assets/theme_example.png +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/colors.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/palettes.md +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/docs/stylesheets/extra.css +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/examples/altair_showcase.py +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/mkdocs.yml +0 -0
- {charite_plot-0.2.0 → charite_plot-0.3.0}/pyproject.toml +0 -0
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.3.0] - 2026-07-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `theme_charite` (matplotlib) gained a `background` parameter (sets figure and axes facecolor).
|
|
13
|
+
- Altair now provides a `using()` context manager mirroring the matplotlib one, for scoping the theme to a `with` block.
|
|
14
|
+
- Explicit `__all__` declarations on every module (and the package) to define the public API surface for `from charite_plot import *` and tooling.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **Unified API across backends.** The matplotlib activate function was renamed `apply_theme(params)` → `enable(**kwargs)`, and `using()` now takes theme keyword arguments instead of a pre-built dict — matching the Altair backend. Migrate `apply_theme(theme_charite(palette="x"))` to `enable(palette="x")` and `using(theme_charite(palette="x"))` to `using(palette="x")`. `theme_charite()` still returns a plain dict if you prefer to apply it manually via `mpl.rcParams.update()`.
|
|
19
|
+
|
|
20
|
+
### Removed
|
|
21
|
+
|
|
22
|
+
- `mpl_themes.apply_theme()` — replaced by `mpl_themes.enable()` (see above).
|
|
23
|
+
|
|
8
24
|
## [0.2.0] - 2026-07-01
|
|
9
25
|
|
|
10
26
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: charite-plot
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Matplotlib and Altair themes for Charité – Universitätsmedizin Berlin
|
|
5
5
|
Project-URL: Homepage, https://github.com/pedramezani/charite-plot
|
|
6
6
|
Project-URL: Documentation, https://pedramezani.github.io/charite-plot
|
|
@@ -53,6 +53,13 @@ Description-Content-Type: text/markdown
|
|
|
53
53
|
|
|
54
54
|
# charite-plot
|
|
55
55
|
|
|
56
|
+

|
|
57
|
+

|
|
58
|
+

|
|
59
|
+

|
|
60
|
+

|
|
61
|
+

|
|
62
|
+
|
|
56
63
|
A Python package with a Charité-styled Matplotlib theme, [visual identity](https://marke.charite.de/d/Y3FxSwD6Tz3a) colour palettes, and an Altair theme — ported from the [`charite` R package](https://github.com/johannesjuliusm/charite).
|
|
57
64
|
|
|
58
65
|
## Installation
|
|
@@ -82,9 +89,9 @@ Preview the available colour palettes.
|
|
|
82
89
|
|
|
83
90
|
```python
|
|
84
91
|
import matplotlib.pyplot as plt
|
|
85
|
-
from charite_plot.mpl_themes import
|
|
92
|
+
from charite_plot.mpl_themes import enable
|
|
86
93
|
|
|
87
|
-
|
|
94
|
+
enable()
|
|
88
95
|
|
|
89
96
|
fig, ax = plt.subplots()
|
|
90
97
|
ax.plot([1, 2, 3], [4, 7, 3])
|
|
@@ -95,9 +102,9 @@ plt.show()
|
|
|
95
102
|
Use as a context manager to scope the theme to a single figure:
|
|
96
103
|
|
|
97
104
|
```python
|
|
98
|
-
from charite_plot.mpl_themes import
|
|
105
|
+
from charite_plot.mpl_themes import using
|
|
99
106
|
|
|
100
|
-
with using(
|
|
107
|
+
with using(palette="goldelse"):
|
|
101
108
|
fig, ax = plt.subplots()
|
|
102
109
|
ax.bar(["A", "B", "C"], [3, 7, 5])
|
|
103
110
|
```
|
|
@@ -123,11 +130,13 @@ enable(palette="berryseason", font_size=13)
|
|
|
123
130
|
|
|
124
131
|
| Symbol | Description |
|
|
125
132
|
|--------|-------------|
|
|
126
|
-
| `mpl_themes.theme_charite()` | Returns a matplotlib rcParams dict for the Charité theme |
|
|
127
|
-
| `mpl_themes.
|
|
128
|
-
| `mpl_themes.using(
|
|
129
|
-
| `altair_themes.theme_charite()` | Returns a Vega-Lite config dict for the Charité theme |
|
|
133
|
+
| `mpl_themes.theme_charite(**kwargs)` | Returns a matplotlib rcParams dict for the Charité theme |
|
|
134
|
+
| `mpl_themes.enable(**kwargs)` | Applies the theme permanently to `rcParams` |
|
|
135
|
+
| `mpl_themes.using(**kwargs)` | Context manager: applies the theme temporarily |
|
|
136
|
+
| `altair_themes.theme_charite(**kwargs)` | Returns a Vega-Lite config dict for the Charité theme |
|
|
130
137
|
| `altair_themes.enable(**kwargs)` | Registers and enables the theme in Altair |
|
|
138
|
+
| `altair_themes.using(**kwargs)` | Context manager: enables the theme temporarily |
|
|
139
|
+
| `altair_themes.register()` | Registers the theme without enabling it (Altair-only) |
|
|
131
140
|
| `PALETTES` | Dict of 10 named colour palettes |
|
|
132
141
|
| `make_palette(name, n, reverse)` | Subsample or interpolate any palette |
|
|
133
142
|
| `CHARITE_COLORS` | Dict of all 27 hex colour constants |
|
|
@@ -141,7 +150,7 @@ The fallback chain follows the official Charité brand guidelines:
|
|
|
141
150
|
`DejaVu Sans` ships with Matplotlib and is always available as the penultimate fallback; `sans-serif` lets the browser or system choose if nothing else matches (important for Altair/Vega-Lite). To override the preferred font:
|
|
142
151
|
|
|
143
152
|
```python
|
|
144
|
-
|
|
153
|
+
enable(font="Arial")
|
|
145
154
|
```
|
|
146
155
|
|
|
147
156
|
## How to cite
|
|
@@ -153,7 +162,7 @@ If you use charite-plot in your work, please cite it as:
|
|
|
153
162
|
author = {Ramezani, Pedram},
|
|
154
163
|
title = {charite-plot: Matplotlib and Altair Themes for Charité – Universitätsmedizin Berlin},
|
|
155
164
|
year = {2026},
|
|
156
|
-
version = {0.
|
|
165
|
+
version = {0.3.0},
|
|
157
166
|
url = {https://github.com/pedramezani/charite-plot},
|
|
158
167
|
license = {MIT},
|
|
159
168
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# charite-plot
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
3
10
|
A Python package with a Charité-styled Matplotlib theme, [visual identity](https://marke.charite.de/d/Y3FxSwD6Tz3a) colour palettes, and an Altair theme — ported from the [`charite` R package](https://github.com/johannesjuliusm/charite).
|
|
4
11
|
|
|
5
12
|
## Installation
|
|
@@ -29,9 +36,9 @@ Preview the available colour palettes.
|
|
|
29
36
|
|
|
30
37
|
```python
|
|
31
38
|
import matplotlib.pyplot as plt
|
|
32
|
-
from charite_plot.mpl_themes import
|
|
39
|
+
from charite_plot.mpl_themes import enable
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
enable()
|
|
35
42
|
|
|
36
43
|
fig, ax = plt.subplots()
|
|
37
44
|
ax.plot([1, 2, 3], [4, 7, 3])
|
|
@@ -42,9 +49,9 @@ plt.show()
|
|
|
42
49
|
Use as a context manager to scope the theme to a single figure:
|
|
43
50
|
|
|
44
51
|
```python
|
|
45
|
-
from charite_plot.mpl_themes import
|
|
52
|
+
from charite_plot.mpl_themes import using
|
|
46
53
|
|
|
47
|
-
with using(
|
|
54
|
+
with using(palette="goldelse"):
|
|
48
55
|
fig, ax = plt.subplots()
|
|
49
56
|
ax.bar(["A", "B", "C"], [3, 7, 5])
|
|
50
57
|
```
|
|
@@ -70,11 +77,13 @@ enable(palette="berryseason", font_size=13)
|
|
|
70
77
|
|
|
71
78
|
| Symbol | Description |
|
|
72
79
|
|--------|-------------|
|
|
73
|
-
| `mpl_themes.theme_charite()` | Returns a matplotlib rcParams dict for the Charité theme |
|
|
74
|
-
| `mpl_themes.
|
|
75
|
-
| `mpl_themes.using(
|
|
76
|
-
| `altair_themes.theme_charite()` | Returns a Vega-Lite config dict for the Charité theme |
|
|
80
|
+
| `mpl_themes.theme_charite(**kwargs)` | Returns a matplotlib rcParams dict for the Charité theme |
|
|
81
|
+
| `mpl_themes.enable(**kwargs)` | Applies the theme permanently to `rcParams` |
|
|
82
|
+
| `mpl_themes.using(**kwargs)` | Context manager: applies the theme temporarily |
|
|
83
|
+
| `altair_themes.theme_charite(**kwargs)` | Returns a Vega-Lite config dict for the Charité theme |
|
|
77
84
|
| `altair_themes.enable(**kwargs)` | Registers and enables the theme in Altair |
|
|
85
|
+
| `altair_themes.using(**kwargs)` | Context manager: enables the theme temporarily |
|
|
86
|
+
| `altair_themes.register()` | Registers the theme without enabling it (Altair-only) |
|
|
78
87
|
| `PALETTES` | Dict of 10 named colour palettes |
|
|
79
88
|
| `make_palette(name, n, reverse)` | Subsample or interpolate any palette |
|
|
80
89
|
| `CHARITE_COLORS` | Dict of all 27 hex colour constants |
|
|
@@ -88,7 +97,7 @@ The fallback chain follows the official Charité brand guidelines:
|
|
|
88
97
|
`DejaVu Sans` ships with Matplotlib and is always available as the penultimate fallback; `sans-serif` lets the browser or system choose if nothing else matches (important for Altair/Vega-Lite). To override the preferred font:
|
|
89
98
|
|
|
90
99
|
```python
|
|
91
|
-
|
|
100
|
+
enable(font="Arial")
|
|
92
101
|
```
|
|
93
102
|
|
|
94
103
|
## How to cite
|
|
@@ -100,7 +109,7 @@ If you use charite-plot in your work, please cite it as:
|
|
|
100
109
|
author = {Ramezani, Pedram},
|
|
101
110
|
title = {charite-plot: Matplotlib and Altair Themes for Charité – Universitätsmedizin Berlin},
|
|
102
111
|
year = {2026},
|
|
103
|
-
version = {0.
|
|
112
|
+
version = {0.3.0},
|
|
104
113
|
url = {https://github.com/pedramezani/charite-plot},
|
|
105
114
|
license = {MIT},
|
|
106
115
|
}
|
|
@@ -5,12 +5,12 @@ Quick start
|
|
|
5
5
|
Matplotlib::
|
|
6
6
|
|
|
7
7
|
import matplotlib.pyplot as plt
|
|
8
|
-
from charite_plot.mpl_themes import
|
|
8
|
+
from charite_plot.mpl_themes import enable
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
enable() # permanent
|
|
11
11
|
# or temporarily:
|
|
12
12
|
from charite_plot.mpl_themes import using
|
|
13
|
-
with using(
|
|
13
|
+
with using(palette="goldelse"):
|
|
14
14
|
fig, ax = plt.subplots()
|
|
15
15
|
ax.plot([1, 2, 3])
|
|
16
16
|
|
|
@@ -21,10 +21,19 @@ Altair::
|
|
|
21
21
|
# charts rendered after this call use the theme automatically
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
from .colors import * # noqa:
|
|
25
|
-
from .
|
|
26
|
-
from . import
|
|
27
|
-
from . import
|
|
24
|
+
from .colors import * # noqa: F403 (all color constants + CHARITE_COLORS)
|
|
25
|
+
from .colors import __all__ as _COLOR_ALL
|
|
26
|
+
from .palettes import PALETTES, make_palette
|
|
27
|
+
from . import mpl_themes
|
|
28
|
+
from . import altair_themes
|
|
28
29
|
|
|
29
|
-
__version__ = "0.
|
|
30
|
+
__version__ = "0.3.0"
|
|
30
31
|
__author__ = "Pedram Ramezani"
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
*_COLOR_ALL,
|
|
35
|
+
"PALETTES",
|
|
36
|
+
"make_palette",
|
|
37
|
+
"mpl_themes",
|
|
38
|
+
"altair_themes",
|
|
39
|
+
]
|
|
@@ -8,6 +8,8 @@ ratios are shared so both backends scale identically from their base size
|
|
|
8
8
|
|
|
9
9
|
from typing import NamedTuple
|
|
10
10
|
|
|
11
|
+
__all__ = ["FontSizes", "Margins", "Thickness", "resolve_font_sizes"]
|
|
12
|
+
|
|
11
13
|
|
|
12
14
|
class FontSizes(NamedTuple):
|
|
13
15
|
"""Derived font sizes, all scaled from the base ``font_size``."""
|
|
@@ -10,6 +10,9 @@ Register and enable with::
|
|
|
10
10
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from uuid import uuid4
|
|
15
|
+
|
|
13
16
|
from .colors import (
|
|
14
17
|
BLACK, WHITE, TEXT_GREY, PRIME_BLUE, PRIME_LGREY,
|
|
15
18
|
SECOND_DBLUE, KORALL,
|
|
@@ -23,6 +26,8 @@ from typing import TYPE_CHECKING
|
|
|
23
26
|
if TYPE_CHECKING:
|
|
24
27
|
from altair.theme import AxisConfigKwds, ThemeConfig
|
|
25
28
|
|
|
29
|
+
__all__ = ["theme_charite", "enable", "using", "register"]
|
|
30
|
+
|
|
26
31
|
|
|
27
32
|
def _css_font_stack(preferred: str | None) -> str:
|
|
28
33
|
"""Return a CSS font-family string (comma-separated, quoted if needed)."""
|
|
@@ -184,3 +189,39 @@ def enable(**kwargs) -> None:
|
|
|
184
189
|
import altair as alt
|
|
185
190
|
func = (lambda: theme_charite(**kwargs)) if kwargs else theme_charite
|
|
186
191
|
alt.theme.register("charite", enable=True)(func)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
@contextmanager
|
|
195
|
+
def using(**kwargs):
|
|
196
|
+
"""Temporarily enable the Charité theme, restoring the previous theme on exit.
|
|
197
|
+
|
|
198
|
+
Mirrors :func:`charite_plot.mpl_themes.using`. Charts created (or serialised
|
|
199
|
+
with ``chart.to_json()`` / ``chart.to_dict()``) inside the ``with`` block use
|
|
200
|
+
the Charité theme; the previously active theme is restored afterwards.
|
|
201
|
+
|
|
202
|
+
Parameters
|
|
203
|
+
----------
|
|
204
|
+
**kwargs:
|
|
205
|
+
Any parameter accepted by ``theme_charite``.
|
|
206
|
+
|
|
207
|
+
Examples
|
|
208
|
+
--------
|
|
209
|
+
```python
|
|
210
|
+
from charite_plot.altair_themes import using
|
|
211
|
+
with using(palette="goldelse"):
|
|
212
|
+
spec = chart.to_json()
|
|
213
|
+
```
|
|
214
|
+
"""
|
|
215
|
+
import altair as alt
|
|
216
|
+
func = (lambda: theme_charite(**kwargs)) if kwargs else theme_charite
|
|
217
|
+
# Register under a unique throwaway name so we don't clobber the primary
|
|
218
|
+
# "charite" registration and so nested ``using`` blocks don't collide.
|
|
219
|
+
# ``alt.theme.enable`` restores the previous theme on exit; the temporary
|
|
220
|
+
# registration is removed afterwards to keep the registry clean.
|
|
221
|
+
name = f"_charite_{uuid4().hex}"
|
|
222
|
+
alt.theme.register(name, enable=False)(func)
|
|
223
|
+
try:
|
|
224
|
+
with alt.theme.enable(name):
|
|
225
|
+
yield
|
|
226
|
+
finally:
|
|
227
|
+
alt.theme.unregister(name)
|
|
@@ -9,6 +9,8 @@ from .palettes import PALETTES
|
|
|
9
9
|
from .fonts import build_font_stack
|
|
10
10
|
from ._theme_common import Margins, Thickness, resolve_font_sizes
|
|
11
11
|
|
|
12
|
+
__all__ = ["theme_charite", "enable", "using"]
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
def theme_charite(
|
|
14
16
|
font: str | None = None,
|
|
@@ -16,8 +18,9 @@ def theme_charite(
|
|
|
16
18
|
thickness: float = 0.5,
|
|
17
19
|
grid: bool = False,
|
|
18
20
|
palette: str | list[str] = "primary",
|
|
19
|
-
|
|
21
|
+
background: str = "white",
|
|
20
22
|
tiny_margins: bool = False,
|
|
23
|
+
interactive: bool = False,
|
|
21
24
|
) -> dict:
|
|
22
25
|
"""Return matplotlib rcParams dict for the Charité corporate identity theme.
|
|
23
26
|
|
|
@@ -35,13 +38,16 @@ def theme_charite(
|
|
|
35
38
|
palette:
|
|
36
39
|
Name of a built-in palette or a list of hex color strings used for the
|
|
37
40
|
``axes.prop_cycle``.
|
|
41
|
+
background:
|
|
42
|
+
Figure and axes background color.
|
|
43
|
+
tiny_margins:
|
|
44
|
+
Minimise all margins around the plot panel. Useful for dense layouts or
|
|
45
|
+
when saving figures with little surrounding whitespace.
|
|
38
46
|
interactive:
|
|
39
47
|
Enable matplotlib interactive mode (equivalent to ``plt.ion()``).
|
|
40
48
|
Useful in notebooks or scripts where you want plots to display
|
|
41
|
-
without blocking.
|
|
42
|
-
|
|
43
|
-
Minimise all margins around the plot panel. Useful for dense layouts or
|
|
44
|
-
when saving figures with little surrounding whitespace.
|
|
49
|
+
without blocking. Matplotlib-specific (Altair charts use
|
|
50
|
+
``.interactive()``).
|
|
45
51
|
"""
|
|
46
52
|
sans_font_stack = build_font_stack(preferred=font)
|
|
47
53
|
monospace_font_stack = ["Andale Mono", "Nimbus Mono L", "Courier New", "Courier", "Fixed", "Terminal", "monospace"]
|
|
@@ -82,7 +88,7 @@ def theme_charite(
|
|
|
82
88
|
"axes.labelcolor": TEXT_GREY,
|
|
83
89
|
"axes.labelpad": MARGINS.label,
|
|
84
90
|
"axes.edgecolor": BLACK,
|
|
85
|
-
"axes.facecolor":
|
|
91
|
+
"axes.facecolor": background,
|
|
86
92
|
"axes.grid": grid,
|
|
87
93
|
"axes.axisbelow": True,
|
|
88
94
|
"axes.spines.top": False,
|
|
@@ -123,8 +129,8 @@ def theme_charite(
|
|
|
123
129
|
"text.antialiased": True,
|
|
124
130
|
|
|
125
131
|
# Figure
|
|
126
|
-
"figure.facecolor":
|
|
127
|
-
"figure.edgecolor":
|
|
132
|
+
"figure.facecolor": background,
|
|
133
|
+
"figure.edgecolor": background,
|
|
128
134
|
"figure.dpi": 100,
|
|
129
135
|
"figure.figsize": (11, 8),
|
|
130
136
|
"figure.subplot.hspace": MARGINS.hspace,
|
|
@@ -165,24 +171,45 @@ def theme_charite(
|
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
|
|
168
|
-
def
|
|
169
|
-
"""Apply
|
|
174
|
+
def enable(**kwargs) -> None:
|
|
175
|
+
"""Apply the Charité theme to matplotlib's global rcParams (permanent until reset).
|
|
176
|
+
|
|
177
|
+
Parameters
|
|
178
|
+
----------
|
|
179
|
+
**kwargs:
|
|
180
|
+
Any parameter accepted by :func:`theme_charite` (``font``,
|
|
181
|
+
``font_size``, ``thickness``, ``grid``, ``palette``, ``background``,
|
|
182
|
+
``tiny_margins``, ``interactive``).
|
|
183
|
+
|
|
184
|
+
Examples
|
|
185
|
+
--------
|
|
186
|
+
```python
|
|
187
|
+
from charite_plot.mpl_themes import enable
|
|
188
|
+
enable(palette="goldelse", font_size=8)
|
|
189
|
+
```
|
|
190
|
+
"""
|
|
170
191
|
import matplotlib as mpl
|
|
171
|
-
mpl.rcParams.update(
|
|
192
|
+
mpl.rcParams.update(theme_charite(**kwargs))
|
|
172
193
|
|
|
173
194
|
|
|
174
195
|
@contextmanager
|
|
175
|
-
def using(
|
|
176
|
-
"""
|
|
196
|
+
def using(**kwargs):
|
|
197
|
+
"""Temporarily apply the Charité theme, restoring the previous rcParams on exit.
|
|
198
|
+
|
|
199
|
+
Parameters
|
|
200
|
+
----------
|
|
201
|
+
**kwargs:
|
|
202
|
+
Any parameter accepted by :func:`theme_charite`.
|
|
177
203
|
|
|
178
204
|
Examples
|
|
179
205
|
--------
|
|
180
206
|
```python
|
|
181
|
-
|
|
207
|
+
from charite_plot.mpl_themes import using
|
|
208
|
+
with using(palette="goldelse"):
|
|
182
209
|
fig, ax = plt.subplots()
|
|
183
210
|
ax.plot([1, 2, 3])
|
|
184
211
|
```
|
|
185
212
|
"""
|
|
186
213
|
import matplotlib as mpl
|
|
187
|
-
with mpl.rc_context(
|
|
214
|
+
with mpl.rc_context(theme_charite(**kwargs)):
|
|
188
215
|
yield
|
|
@@ -9,7 +9,7 @@ If you use charite-plot in your research or work, please cite it. A `CITATION.cf
|
|
|
9
9
|
author = {Ramezani, Pedram},
|
|
10
10
|
title = {charite-plot: Matplotlib and Altair Themes for Charité – Universitätsmedizin Berlin},
|
|
11
11
|
year = {2026},
|
|
12
|
-
version = {0.
|
|
12
|
+
version = {0.3.0},
|
|
13
13
|
url = {https://github.com/pedramezani/charite-plot},
|
|
14
14
|
license = {MIT},
|
|
15
15
|
}
|
|
@@ -22,9 +22,9 @@ Preview the available colour palettes.
|
|
|
22
22
|
|
|
23
23
|
```python
|
|
24
24
|
import matplotlib.pyplot as plt
|
|
25
|
-
from charite_plot.mpl_themes import
|
|
25
|
+
from charite_plot.mpl_themes import enable
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
enable()
|
|
28
28
|
|
|
29
29
|
fig, ax = plt.subplots()
|
|
30
30
|
ax.plot([1, 2, 3], [4, 7, 3])
|
|
@@ -35,9 +35,9 @@ plt.show()
|
|
|
35
35
|
Use as a context manager to scope the theme to a single figure:
|
|
36
36
|
|
|
37
37
|
```python
|
|
38
|
-
from charite_plot.mpl_themes import
|
|
38
|
+
from charite_plot.mpl_themes import using
|
|
39
39
|
|
|
40
|
-
with using(
|
|
40
|
+
with using(palette="goldelse"):
|
|
41
41
|
fig, ax = plt.subplots()
|
|
42
42
|
ax.bar(["A", "B", "C"], [3, 7, 5])
|
|
43
43
|
```
|
|
@@ -58,5 +58,5 @@ chart = alt.Chart(df).mark_bar().encode(...)
|
|
|
58
58
|
## Design principles
|
|
59
59
|
|
|
60
60
|
- **Single source of truth** — colors are defined once in `colors.py` and imported by every other module.
|
|
61
|
-
- **No side effects on import** — theme functions return plain dicts; you opt in with `
|
|
61
|
+
- **No side effects on import** — theme functions return plain dicts; you opt in with `enable()` or `using()`.
|
|
62
62
|
- **Font fallback** — if Charité Text Office is not installed, the theme cascades to Charit? Text Office, then Calibri, DejaVu Sans, and finally sans-serif automatically, following the official brand guidelines.
|
|
@@ -37,9 +37,9 @@ charite-plot works out of the box with any system. The font fallback chain is:
|
|
|
37
37
|
To use a different preferred font, pass it explicitly:
|
|
38
38
|
|
|
39
39
|
```python
|
|
40
|
-
from charite_plot.mpl_themes import
|
|
40
|
+
from charite_plot.mpl_themes import enable
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
enable(font="Arial")
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
A warning is shown if the requested font cannot be found on the system.
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Applying the theme
|
|
4
4
|
|
|
5
|
-
### Permanently — `
|
|
5
|
+
### Permanently — `enable`
|
|
6
6
|
|
|
7
7
|
Sets rcParams globally for the rest of the session:
|
|
8
8
|
|
|
9
9
|
```python
|
|
10
10
|
import matplotlib.pyplot as plt
|
|
11
|
-
from charite_plot.mpl_themes import
|
|
11
|
+
from charite_plot.mpl_themes import enable
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
enable()
|
|
14
14
|
|
|
15
15
|
fig, ax = plt.subplots()
|
|
16
16
|
ax.plot([1, 2, 3], [4, 7, 3])
|
|
@@ -25,9 +25,9 @@ plt.show()
|
|
|
25
25
|
Applies the theme only inside the `with` block, then restores the previous rcParams:
|
|
26
26
|
|
|
27
27
|
```python
|
|
28
|
-
from charite_plot.mpl_themes import
|
|
28
|
+
from charite_plot.mpl_themes import using
|
|
29
29
|
|
|
30
|
-
with using(
|
|
30
|
+
with using(palette="goldelse"):
|
|
31
31
|
fig, ax = plt.subplots()
|
|
32
32
|
ax.bar(["A", "B", "C", "D"], [3, 7, 5, 9])
|
|
33
33
|
```
|
|
@@ -57,8 +57,9 @@ mpl.rcParams.update(params)
|
|
|
57
57
|
| `thickness` | `float` | `0.5` | Axis line and tick width. |
|
|
58
58
|
| `grid` | `bool` | `False` | Show major grid lines. |
|
|
59
59
|
| `palette` | `str | list[str]` | `"primary"` | Named palette or list of hex strings for `axes.prop_cycle`. |
|
|
60
|
-
| `
|
|
60
|
+
| `background` | `str` | `"white"` | Figure and axes background color. |
|
|
61
61
|
| `tiny_margins` | `bool` | `False` | Minimise all margins and paddings around the plot panel. Useful for dense layouts. |
|
|
62
|
+
| `interactive` | `bool` | `False` | Enable interactive mode (equivalent to `plt.ion()`). Matplotlib-specific. |
|
|
62
63
|
|
|
63
64
|
---
|
|
64
65
|
|
|
@@ -67,37 +68,37 @@ mpl.rcParams.update(params)
|
|
|
67
68
|
### Palette switcher
|
|
68
69
|
|
|
69
70
|
```python
|
|
70
|
-
from charite_plot.mpl_themes import
|
|
71
|
+
from charite_plot.mpl_themes import enable
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
enable(palette="berryseason")
|
|
73
74
|
```
|
|
74
75
|
|
|
75
76
|
### Custom font size for a journal figure
|
|
76
77
|
|
|
77
78
|
```python
|
|
78
|
-
|
|
79
|
+
enable(font_size=8, thickness=0.4)
|
|
79
80
|
```
|
|
80
81
|
|
|
81
82
|
### Custom color list
|
|
82
83
|
|
|
83
84
|
```python
|
|
84
|
-
|
|
85
|
+
enable(palette=["#004d9b", "#ea5451", "#fab600"])
|
|
85
86
|
```
|
|
86
87
|
|
|
87
88
|
### Grid on
|
|
88
89
|
|
|
89
90
|
```python
|
|
90
|
-
|
|
91
|
+
enable(grid=True)
|
|
91
92
|
```
|
|
92
93
|
|
|
93
94
|
### Dense layout with minimal margins
|
|
94
95
|
|
|
95
96
|
```python
|
|
96
|
-
|
|
97
|
+
enable(tiny_margins=True)
|
|
97
98
|
```
|
|
98
99
|
|
|
99
100
|
### Interactive mode (notebooks / REPL)
|
|
100
101
|
|
|
101
102
|
```python
|
|
102
|
-
|
|
103
|
+
enable(interactive=True) # equivalent to plt.ion()
|
|
103
104
|
```
|
|
@@ -13,7 +13,7 @@ import matplotlib.pyplot as plt
|
|
|
13
13
|
import matplotlib.patches as mpatches
|
|
14
14
|
import matplotlib.ticker as mticker
|
|
15
15
|
|
|
16
|
-
from charite_plot.mpl_themes import
|
|
16
|
+
from charite_plot.mpl_themes import enable
|
|
17
17
|
from charite_plot.palettes import PALETTES
|
|
18
18
|
|
|
19
19
|
rng = np.random.default_rng(42)
|
|
@@ -28,7 +28,7 @@ COMMON = {
|
|
|
28
28
|
MARKERS = {"A": "o", "B": "s", "C": "^"}
|
|
29
29
|
|
|
30
30
|
# ── apply theme globally ───────────────────────────────────────────────────
|
|
31
|
-
|
|
31
|
+
enable(palette="primary")
|
|
32
32
|
COLORS = PALETTES["primary"]
|
|
33
33
|
|
|
34
34
|
# ── figure layout ──────────────────────────────────────────────────────────
|
|
@@ -14,10 +14,10 @@ sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
|
|
|
14
14
|
import matplotlib.pyplot as plt
|
|
15
15
|
import matplotlib.patches as mpatches
|
|
16
16
|
|
|
17
|
-
from charite_plot.mpl_themes import
|
|
17
|
+
from charite_plot.mpl_themes import enable
|
|
18
18
|
from charite_plot.palettes import PALETTES
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
enable()
|
|
21
21
|
|
|
22
22
|
MAX_COLS = max(len(p) for p in PALETTES.values())
|
|
23
23
|
names = list(PALETTES.keys())
|
|
@@ -18,7 +18,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
|
|
|
18
18
|
import numpy as np
|
|
19
19
|
import matplotlib.pyplot as plt
|
|
20
20
|
|
|
21
|
-
from charite_plot.mpl_themes import
|
|
21
|
+
from charite_plot.mpl_themes import enable
|
|
22
22
|
from charite_plot.colors import PRIME_BLUE, PRIME_DGREY, KORALL, TEXT_GREY
|
|
23
23
|
|
|
24
24
|
COLORS = [KORALL, PRIME_BLUE, PRIME_DGREY] # C1, C2, C3
|
|
@@ -94,7 +94,7 @@ t_axis, means, ses = _generate_data()
|
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
# ── single: Charité theme ───────────────────────────────────────────────────
|
|
97
|
-
|
|
97
|
+
enable(font_size=14, thickness=1)
|
|
98
98
|
|
|
99
99
|
fig, ax = plt.subplots(figsize=(6, 4.5))
|
|
100
100
|
fig.subplots_adjust(top=0.88)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|