figurekit 0.5.1__py3-none-any.whl
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.
- figkit/__init__.py +141 -0
- figkit/access.py +144 -0
- figkit/check.py +227 -0
- figkit/cli.py +180 -0
- figkit/export.py +366 -0
- figkit/fonts/BricolageGrotesque-Regular.ttf +0 -0
- figkit/fonts/BricolageGrotesque-SemiBold.ttf +0 -0
- figkit/fonts/JetBrainsMono-Regular.ttf +0 -0
- figkit/fonts/JetBrainsMono-SemiBold.ttf +0 -0
- figkit/fonts/OFL-BricolageGrotesque.txt +93 -0
- figkit/fonts/OFL-JetBrainsMono.txt +93 -0
- figkit/helpers.py +404 -0
- figkit/language.py +126 -0
- figkit/manifest.py +188 -0
- figkit/preview.py +103 -0
- figkit/project.py +173 -0
- figkit/py.typed +0 -0
- figkit/theme.py +524 -0
- figkit/tokens.json +52 -0
- figkit/tokens.schema.json +95 -0
- figurekit-0.5.1.dist-info/METADATA +439 -0
- figurekit-0.5.1.dist-info/RECORD +27 -0
- figurekit-0.5.1.dist-info/WHEEL +4 -0
- figurekit-0.5.1.dist-info/entry_points.txt +2 -0
- figurekit-0.5.1.dist-info/licenses/LICENSE +21 -0
- figurekit-0.5.1.dist-info/licenses/src/figkit/fonts/OFL-BricolageGrotesque.txt +93 -0
- figurekit-0.5.1.dist-info/licenses/src/figkit/fonts/OFL-JetBrainsMono.txt +93 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: figurekit
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: One figure style for every project: light and dark themes, transparent SVG and PNG, Bricolage Grotesque and JetBrains Mono, reproducible files.
|
|
5
|
+
Project-URL: Repository, https://github.com/BenBotsch/FigureKit
|
|
6
|
+
Project-URL: Issues, https://github.com/BenBotsch/FigureKit/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/BenBotsch/FigureKit/blob/main/CHANGELOG.md
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: src/figkit/fonts/OFL-BricolageGrotesque.txt
|
|
11
|
+
License-File: src/figkit/fonts/OFL-JetBrainsMono.txt
|
|
12
|
+
Keywords: dark mode,figures,matplotlib,plotting,style,svg
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Framework :: Matplotlib
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.12
|
|
24
|
+
Requires-Dist: matplotlib>=3.9
|
|
25
|
+
Requires-Dist: numpy>=1.26
|
|
26
|
+
Requires-Dist: pillow>=10.4
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
<div align="center">
|
|
30
|
+
|
|
31
|
+
# FigureKit
|
|
32
|
+
|
|
33
|
+
**Publication-ready matplotlib figures in one consistent style, for READMEs, websites and slides.**
|
|
34
|
+
|
|
35
|
+
[](https://github.com/BenBotsch/FigureKit/actions/workflows/ci.yml)
|
|
36
|
+
[](https://github.com/BenBotsch/FigureKit/releases)
|
|
37
|
+

|
|
38
|
+
[](https://github.com/BenBotsch/FigureKit/blob/main/LICENSE)
|
|
39
|
+
|
|
40
|
+
[Quickstart](#quickstart) · [Recipes](#recipes) · [Websites](#figures-for-a-website) ·
|
|
41
|
+
[Your own style](#a-style-of-your-own) · [CLI](#command-line) · [API](#api)
|
|
42
|
+
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
A figure is a function of the theme. FigureKit draws it once per theme, such as light and dark,
|
|
46
|
+
and once per language, writes transparent SVG and PNG files that are byte-identical on every
|
|
47
|
+
run, and checks them in CI.
|
|
48
|
+
|
|
49
|
+
<table>
|
|
50
|
+
<tr>
|
|
51
|
+
<th>Plain matplotlib</th>
|
|
52
|
+
<th>With FigureKit</th>
|
|
53
|
+
</tr>
|
|
54
|
+
<tr>
|
|
55
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/readme/before.svg" alt="The bar chart of recall per class in the default matplotlib style: blue bars, a thin line at 0.8, no values."></td>
|
|
56
|
+
<td width="50%"><picture>
|
|
57
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/examples/bars-dark.svg">
|
|
58
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/bars.svg" alt="The same bar chart with FigureKit: title and subtitle, values at the bars, a labelled target line at 80 % and percent ticks.">
|
|
59
|
+
</picture></td>
|
|
60
|
+
</tr>
|
|
61
|
+
</table>
|
|
62
|
+
|
|
63
|
+
## Features
|
|
64
|
+
|
|
65
|
+
- **One style, many projects.** The bundled style matches the portfolio, with Bricolage Grotesque
|
|
66
|
+
and JetBrains Mono for numbers, both bundled. A project brings its own style with any number of
|
|
67
|
+
themes in one JSON file.
|
|
68
|
+
- **Light and dark, transparent.** One file per theme fits every page colour of that theme:
|
|
69
|
+
|
|
70
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/readme/modes.png" alt="The bar chart twice, the light file on the light page colour and the dark file on the dark page colour.">
|
|
71
|
+
|
|
72
|
+
- **Accessible.** Series colours are validated for colour-vision deficiencies against the page
|
|
73
|
+
colours; text colours reach WCAG contrast, checked in the tests. Text below 8 pt is an error.
|
|
74
|
+
- **Reproducible.** The same figure gives byte-identical SVGs on Linux and Windows, without date
|
|
75
|
+
or version, so diffs show only real changes.
|
|
76
|
+
- **Two languages.** Website figures come without title in every language, German numbers
|
|
77
|
+
included, with a `figures.json` of titles and alt texts.
|
|
78
|
+
- **Checked in CI.** `figkit check` fails on missing theme or language pairs, opaque backgrounds,
|
|
79
|
+
figures off the canvas, small text, oversized files, missing alt texts and page colours that
|
|
80
|
+
differ from the website's stylesheet.
|
|
81
|
+
|
|
82
|
+
### Why not a matplotlib style sheet?
|
|
83
|
+
|
|
84
|
+
A style sheet sets colours and fonts for one look. It does not draw a figure once per theme and
|
|
85
|
+
language, keep files transparent and reproducible, name them for `<picture>` and the website,
|
|
86
|
+
or check in CI that every pair exists and the colours match the stylesheet of the website.
|
|
87
|
+
|
|
88
|
+
## Quickstart
|
|
89
|
+
|
|
90
|
+
**1. Install** from PyPI. The package is called `figurekit`, the module and the command `figkit`.
|
|
91
|
+
`uv.lock` pins the version, so a style change reaches a project only when it upgrades:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
uv add figurekit
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**2. Draw** a figure as a function of the theme and let `render` write it:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from pathlib import Path
|
|
101
|
+
|
|
102
|
+
import matplotlib.pyplot as plt
|
|
103
|
+
import figkit
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def recall(theme: figkit.Theme) -> plt.Figure:
|
|
107
|
+
figure, ax = plt.subplots(figsize=(figkit.WEB_WIDTH, 3.2))
|
|
108
|
+
bars = ax.barh(["crazing", "inclusion", "patches"], [0.93, 0.81, 0.99], color=theme.series[0])
|
|
109
|
+
figkit.bar_labels(ax, bars, theme, fmt="{:.0%}")
|
|
110
|
+
figkit.reference_line(ax, 0.8, "target 80 %", theme)
|
|
111
|
+
figkit.category_axis(ax, "y")
|
|
112
|
+
figkit.percent(ax, "x")
|
|
113
|
+
figkit.title(ax, "Recall per class", theme, subtitle="Test split")
|
|
114
|
+
return figure
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
figkit.render(Path("docs/figures"), "recall", recall)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
docs/figures/
|
|
122
|
+
├── recall.svg light, transparent, 6.4 in canvas
|
|
123
|
+
├── recall-dark.svg
|
|
124
|
+
├── recall.png 1600 px wide
|
|
125
|
+
└── recall-dark.png
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**3. Embed** both files; the browser picks the one of its mode:
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<picture>
|
|
132
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/figures/recall-dark.svg">
|
|
133
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/figures/recall.svg" alt="Recall per class: all classes above the 80 % target.">
|
|
134
|
+
</picture>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**4. Check** in CI:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
uv run figkit check docs/figures
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`figkit.styled(theme)` applies the style without writing files, for example in a notebook.
|
|
144
|
+
|
|
145
|
+
## Recipes
|
|
146
|
+
|
|
147
|
+
Each recipe is an excerpt of [`scripts/examples.py`](https://github.com/BenBotsch/FigureKit/blob/main/scripts/examples.py), which draws the whole
|
|
148
|
+
[gallery](https://github.com/BenBotsch/FigureKit/blob/main/docs/examples) from invented data.
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary><b>Lines with labels at their ends</b> instead of a legend lookup</summary>
|
|
152
|
+
|
|
153
|
+
<picture>
|
|
154
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/examples/lines-dark.svg">
|
|
155
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/lines.svg" alt="Line chart: validation macro F1 per epoch for three models, labelled at the line ends.">
|
|
156
|
+
</picture>
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
for slot, (name, score) in enumerate(models.items()):
|
|
160
|
+
ax.plot(epochs, score, color=theme.series[slot], label=name)
|
|
161
|
+
ends.append((epochs[-1], score[-1], f"{name} {score[-1]:.2f}"))
|
|
162
|
+
figkit.title(ax, "Validation macro F1", theme)
|
|
163
|
+
figkit.legend_top(ax)
|
|
164
|
+
figkit.grid(ax, "y")
|
|
165
|
+
figkit.line_labels(ax, ends, theme) # moves labels apart where lines end close together
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
</details>
|
|
169
|
+
|
|
170
|
+
<details>
|
|
171
|
+
<summary><b>Heatmap</b> on the sequential ramp with readable cell values</summary>
|
|
172
|
+
|
|
173
|
+
<picture>
|
|
174
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/examples/heatmap-dark.svg">
|
|
175
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/heatmap.svg" alt="Confusion matrix of true against predicted class on the sequential ramp." width="60%">
|
|
176
|
+
</picture>
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
cmap = figkit.ramp_cmap(theme)
|
|
180
|
+
ax.imshow(rates, cmap=cmap, vmin=0, vmax=1)
|
|
181
|
+
for (i, j), count in np.ndenumerate(counts):
|
|
182
|
+
cell = figkit.hex_colour(cmap(rates[i, j]))
|
|
183
|
+
figkit.value(ax, j, i, str(count), theme, ha="center", va="center", color=figkit.ink_on(cell))
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
</details>
|
|
187
|
+
|
|
188
|
+
<details>
|
|
189
|
+
<summary><b>Small multiples</b> with shared axes, confidence bands and a callout</summary>
|
|
190
|
+
|
|
191
|
+
<picture>
|
|
192
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/examples/multiples-dark.svg">
|
|
193
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/multiples.svg" alt="Three panels of learning curves, macro F1 against training images, each line with a shaded band; the middle one points out its plateau.">
|
|
194
|
+
</picture>
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
figure, panels = figkit.small_multiples(3, height=2.2) # inner panels drop shared tick labels
|
|
198
|
+
for slot, (ax, (name, mean, spread)) in enumerate(zip(panels, curves)):
|
|
199
|
+
ax.plot(sizes, mean, color=theme.series[slot], marker="o", markersize=3)
|
|
200
|
+
figkit.band(ax, sizes, mean - spread, mean + spread, theme, slot=slot)
|
|
201
|
+
figkit.callout(panels[1], "plateau", (3200, plateau), (-22, -22), theme)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`figkit.error_bars(ax, x, y, error, theme)` draws thin bars without caps in the secondary ink
|
|
205
|
+
for points instead of lines.
|
|
206
|
+
|
|
207
|
+
</details>
|
|
208
|
+
|
|
209
|
+
<details>
|
|
210
|
+
<summary><b>Social card</b> for Open Graph, 1200 x 630</summary>
|
|
211
|
+
|
|
212
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/card.png" alt="Social card with a project title, a one-line summary and three tiles: accuracy 0.97, latency p95 4.1 ms, model size 11 MB." width="70%">
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
def card(theme: figkit.Theme) -> plt.Figure:
|
|
216
|
+
figure = plt.figure(figsize=figkit.CARD_INCHES)
|
|
217
|
+
...
|
|
218
|
+
ax.text(x, y, "0.97", fontsize=26, fontfamily=figkit.mono(theme))
|
|
219
|
+
return figure
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
figkit.render(out, "card", card, outputs=figkit.CARD) # opaque PNG
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
</details>
|
|
226
|
+
|
|
227
|
+
<details>
|
|
228
|
+
<summary><b>Notebook</b> without files</summary>
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
with figkit.styled(figkit.DARK):
|
|
232
|
+
figure = recall(figkit.DARK)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
</details>
|
|
236
|
+
|
|
237
|
+
## Outputs
|
|
238
|
+
|
|
239
|
+
| Output | Files |
|
|
240
|
+
| --- | --- |
|
|
241
|
+
| `WEB` (default) | transparent SVG and PNG on a 6.4 in canvas, the PNG 1600 px wide |
|
|
242
|
+
| `PHOTO` | transparent WebP and PNG, for images and overlays |
|
|
243
|
+
| `CARD` | opaque 1200 x 630 PNG for Open Graph; draw on `CARD_INCHES` |
|
|
244
|
+
|
|
245
|
+
## Figures for a website
|
|
246
|
+
|
|
247
|
+
The website shows the title as text, so its files leave it out. `page` draws the figure once per
|
|
248
|
+
language, the draw function receives the language as its first argument, and `write_manifest`
|
|
249
|
+
lists the files with their texts:
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
TEXT = {
|
|
253
|
+
"en": figkit.Caption("Recall per class", "All classes above 80 % but scale."),
|
|
254
|
+
"de": figkit.Caption("Recall je Klasse", "Alle Klassen über 80 % außer Zunder."),
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def recall_page(language: str, theme: figkit.Theme) -> plt.Figure:
|
|
259
|
+
# Labels from a table per language, numbers with figkit.number(0.74, ".0%").
|
|
260
|
+
return draw_recall(LABELS[language], theme)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
out = Path("docs/figures/page")
|
|
264
|
+
figkit.write_manifest(out, [figkit.page(out, "recall", recall_page, TEXT)])
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
```text
|
|
268
|
+
docs/figures/page/
|
|
269
|
+
├── recall.de.svg recall.de-dark.svg
|
|
270
|
+
├── recall.en.svg recall.en-dark.svg
|
|
271
|
+
└── figures.json titles, alt texts and files per language and theme
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
A figure that a separate step draws, because it needs a trained model for example, is written
|
|
275
|
+
there with `page`. `figkit.page_entry(out, name, TEXT, figkit.PHOTO[0])` then reads its entry from
|
|
276
|
+
the files, so one step can still write the manifest of all figures.
|
|
277
|
+
|
|
278
|
+
In German, tick labels, the values of `bar_labels` and `figkit.number` write `0,74`, `1.500` and
|
|
279
|
+
`74 %`; category names and other text come from the project.
|
|
280
|
+
|
|
281
|
+
## A style of your own
|
|
282
|
+
|
|
283
|
+
The bundled style is the portfolio's. Another project describes its own in a tokens file.
|
|
284
|
+
[`docs/examples/style/tokens.json`](https://github.com/BenBotsch/FigureKit/blob/main/docs/examples/style/tokens.json) is a complete example with
|
|
285
|
+
other series colours and a `print` theme; the same line chart in it:
|
|
286
|
+
|
|
287
|
+
<table>
|
|
288
|
+
<tr>
|
|
289
|
+
<th>light, paired with dark</th>
|
|
290
|
+
<th>print, without a pair</th>
|
|
291
|
+
</tr>
|
|
292
|
+
<tr>
|
|
293
|
+
<td width="50%"><picture>
|
|
294
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/examples/style/lines-dark.svg">
|
|
295
|
+
<img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/style/lines.svg" alt="The line chart in the example style with teal, blue and amber lines.">
|
|
296
|
+
</picture></td>
|
|
297
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/BenBotsch/FigureKit/main/docs/examples/style/lines-print.png" alt="The line chart in the print theme of the example style, in black and greys."></td>
|
|
298
|
+
</tr>
|
|
299
|
+
</table>
|
|
300
|
+
|
|
301
|
+
Its outline:
|
|
302
|
+
|
|
303
|
+
```json
|
|
304
|
+
{
|
|
305
|
+
"$schema": "../../../src/figkit/tokens.schema.json",
|
|
306
|
+
"version": 2,
|
|
307
|
+
"default": "light",
|
|
308
|
+
"font": {"sans": "Bricolage Grotesque", "mono": "JetBrains Mono", "size": 9, "…": "…"},
|
|
309
|
+
"themes": {
|
|
310
|
+
"light": {"pair": "dark", "pages": ["#faf8f4", "#ffffff"], "series": ["#0f766e", "…"], "…": "…"},
|
|
311
|
+
"dark": {"pair": "light", "…": "…"},
|
|
312
|
+
"print": {"pages": ["#ffffff"], "…": "…"}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Copy it as a start and point `$schema` to
|
|
318
|
+
[`tokens.schema.json`](https://github.com/BenBotsch/FigureKit/blob/main/src/figkit/tokens.schema.json) for completion and validation in the editor.
|
|
319
|
+
Each theme needs `pages`, `surface`, `ink`, `secondary`, `muted`, `grid`, `axis`, `series`, `ramp`
|
|
320
|
+
and `status`.
|
|
321
|
+
|
|
322
|
+
| Key | Meaning |
|
|
323
|
+
| --- | --- |
|
|
324
|
+
| `default` | Theme whose files carry no suffix; every other theme writes `-<name>`. |
|
|
325
|
+
| `pair` | Theme a page swaps with, such as light and dark. `figkit check` requires the file of the pair; a theme without one stands alone. |
|
|
326
|
+
| `font.files` | Glob patterns of font files, relative to the tokens file; without them the bundled fonts apply. matplotlib keeps one file per family in a process, so own font files need family names of their own. |
|
|
327
|
+
| `css` | Maps custom properties of the website, `--color-text: light-dark(#111111, #eeeeee)`, to tokens such as `["ink"]` or `["pages", 0]`. `figkit check --css` compares the first colour with the default theme and the second with its pair. |
|
|
328
|
+
|
|
329
|
+
`figkit.load_style(path)` rejects unknown keys and lists every problem with its place, such as
|
|
330
|
+
`themes.dark.series[2]: 'blue' is not a #rrggbb colour`. The style goes to `render`, `page`,
|
|
331
|
+
`page_entry` and `check`:
|
|
332
|
+
|
|
333
|
+
```python
|
|
334
|
+
style = figkit.load_style(Path("docs/examples/style/tokens.json"))
|
|
335
|
+
figkit.render(Path("docs/figures"), "lines", lines, style=style)
|
|
336
|
+
# lines.svg, lines-dark.svg, lines-print.svg and the PNGs
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
A project names its style once in its `pyproject.toml`. Scripts read it with
|
|
340
|
+
`figkit.project_style()`, and `figkit check` uses it unless `--style` or `--css` say otherwise:
|
|
341
|
+
|
|
342
|
+
```toml
|
|
343
|
+
[tool.figkit]
|
|
344
|
+
tokens = "figures/tokens.json" # relative to pyproject.toml
|
|
345
|
+
css = "../Website/src/styles/tokens.css"
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
`figkit init` starts such a project: it copies the bundled tokens and their schema to
|
|
349
|
+
`figures/tokens.json` and appends the table. `figkit style preview` then draws every series,
|
|
350
|
+
the ramp and the status colours in each theme, so a change to the tokens shows before a real
|
|
351
|
+
figure uses it.
|
|
352
|
+
|
|
353
|
+
## Command line
|
|
354
|
+
|
|
355
|
+
```sh
|
|
356
|
+
figkit check [DIRECTORY ...] [--a11y] [--css CSS] [--style TOKENS] [--opaque NAME] [--any-width]
|
|
357
|
+
figkit init [--tokens TOKENS] [--css CSS]
|
|
358
|
+
figkit style preview [DIRECTORY] [--style TOKENS]
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
`init` writes the tokens file, default `figures/tokens.json`, and its schema unless the file
|
|
362
|
+
exists, and appends `[tool.figkit]` to the `pyproject.toml` of the working directory. It stops
|
|
363
|
+
if the table is there already. `style preview` renders `style.svg` and `style.png` in every
|
|
364
|
+
theme to `DIRECTORY`, default `figkit-preview`, from `--style` or `[tool.figkit]`. Text below
|
|
365
|
+
the minimum size of the style fails the preview.
|
|
366
|
+
|
|
367
|
+
`check` takes these options:
|
|
368
|
+
|
|
369
|
+
| Option | Effect |
|
|
370
|
+
| --- | --- |
|
|
371
|
+
| `DIRECTORY` | Folders of figures to check: theme and language pairs, transparency, canvas width, text size, file size and `figures.json`. |
|
|
372
|
+
| `--css CSS` | Compares the page, text and line colours with a stylesheet (alias `--tokens`). |
|
|
373
|
+
| `--style TOKENS` | Style that wrote the figures; overrides `[tool.figkit]`. |
|
|
374
|
+
| `--opaque NAME` | Figure that is opaque on purpose; repeatable, default `card`. |
|
|
375
|
+
| `--any-width` | Does not require the fixed canvas width of web figures. |
|
|
376
|
+
| `--a11y` | Checks the colours of the style: text contrast (WCAG), the separation of neighbouring series under protanopia, deuteranopia and normal vision, and an evenly stepped ramp. Works without a directory. |
|
|
377
|
+
|
|
378
|
+
The exit code is 1 on any problem:
|
|
379
|
+
|
|
380
|
+
```console
|
|
381
|
+
$ uv run figkit check docs/figures docs/figures/page
|
|
382
|
+
docs/figures/recall.svg: missing its pair recall-dark.svg
|
|
383
|
+
$ uv run figkit check --css ../Portfolio/src/styles/tokens.css
|
|
384
|
+
../Portfolio/src/styles/tokens.css: ok
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## API
|
|
388
|
+
|
|
389
|
+
<details>
|
|
390
|
+
<summary>All public names, by area</summary>
|
|
391
|
+
|
|
392
|
+
| Area | Names |
|
|
393
|
+
| --- | --- |
|
|
394
|
+
| Render | `render`, `page`, `page_entry`, `write_manifest`, `save`, `path_for`, `canvas`, `styled`, `headless` |
|
|
395
|
+
| Outputs | `WEB`, `PHOTO`, `CARD`, `SVG`, `PNG`, `WEB_WIDTH`, `CARD_INCHES`, `RASTER_DPI` |
|
|
396
|
+
| Helpers | `title`, `legend_top`, `grid`, `percent`, `category_axis`, `mono`, `mono_ticks`, `value`, `bar_labels`, `reference_line`, `line_labels`, `band`, `error_bars`, `callout`, `small_multiples`, `ramp_cmap`, `ink_on`, `hex_colour` |
|
|
397
|
+
| Languages | `Caption`, `language`, `localize`, `number` |
|
|
398
|
+
| Style | `Theme`, `Typography`, `Style`, `StyleError`, `load_style`, `parse_style`, `DEFAULT`, `LIGHT`, `DARK`, `THEMES`, `TYPE`, `tokens`, `rc`, `register_fonts` |
|
|
399
|
+
| Project | `Project`, `project`, `project_style` |
|
|
400
|
+
| Checks | `check_text` and the `figkit check` command |
|
|
401
|
+
|
|
402
|
+
Importing figkit leaves the matplotlib backend alone; a batch job that only writes files can set
|
|
403
|
+
`MPLBACKEND=Agg`.
|
|
404
|
+
|
|
405
|
+
</details>
|
|
406
|
+
|
|
407
|
+
[docs/style-guide.md](https://github.com/BenBotsch/FigureKit/blob/main/docs/style-guide.md) covers which form fits which data, how colours are
|
|
408
|
+
assigned, layout, file names, embedding and alt text. [CHANGELOG.md](https://github.com/BenBotsch/FigureKit/blob/main/CHANGELOG.md) lists what
|
|
409
|
+
changed, breaking changes first; each [release](https://github.com/BenBotsch/FigureKit/releases)
|
|
410
|
+
attaches the wheel.
|
|
411
|
+
|
|
412
|
+
## Development
|
|
413
|
+
|
|
414
|
+
<details>
|
|
415
|
+
<summary>Checks, gallery, fonts and releases</summary>
|
|
416
|
+
|
|
417
|
+
```sh
|
|
418
|
+
uv sync
|
|
419
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy && uv run pytest
|
|
420
|
+
uv run python scripts/examples.py # regenerate the gallery and the README images
|
|
421
|
+
uv run --no-project --with fonttools python scripts/build_fonts.py # rebuild the static fonts
|
|
422
|
+
uv build && bash scripts/check_package.sh # render and check figures with the built wheel
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
A release: move the entries under `Unreleased` in [CHANGELOG.md](https://github.com/BenBotsch/FigureKit/blob/main/CHANGELOG.md) to a new version
|
|
426
|
+
section, set that version in `pyproject.toml` and `uv.lock` (`uv version 0.4.0`), and push the tag
|
|
427
|
+
`v0.4.0`. The release workflow checks that tag and version match, tests the wheel on Ubuntu and
|
|
428
|
+
Windows, uploads the package to PyPI and publishes the GitHub release with the notes of that section.
|
|
429
|
+
|
|
430
|
+
The colours and type sizes of the bundled style live only in
|
|
431
|
+
[src/figkit/tokens.json](https://github.com/BenBotsch/FigureKit/blob/main/src/figkit/tokens.json).
|
|
432
|
+
|
|
433
|
+
</details>
|
|
434
|
+
|
|
435
|
+
## License
|
|
436
|
+
|
|
437
|
+
Code: MIT. Fonts in `src/figkit/fonts`: SIL Open Font License 1.1, see the `OFL-*.txt` files.
|
|
438
|
+
They are static cuts of the variable fonts, made with fontTools from pinned Google Fonts sources.
|
|
439
|
+
Neither font declares a Reserved Font Name.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
figkit/__init__.py,sha256=812V6g9hOytr7lzZ1IxODkWYKbQ5FHCeCGEKWFw5FbQ,2692
|
|
2
|
+
figkit/access.py,sha256=5n1Xb43TBIYVZBg-Ssb2pJ0tobjloXp-CkqUBXaRwlI,5522
|
|
3
|
+
figkit/check.py,sha256=mb6ObIKVT6ZURO-B-J9CoWHJbA8-KVHy5-JrwpwVIMk,9827
|
|
4
|
+
figkit/cli.py,sha256=UJFTFMBjnSQIGxJtIu4VPIut2La6gol5FOK21ZcdNEw,6311
|
|
5
|
+
figkit/export.py,sha256=oKCX8pph4GnRnyQDcpvUaj9dYCsmnaRGV2Yot0hN_E8,15575
|
|
6
|
+
figkit/helpers.py,sha256=RfoS2Kc2xvGKnfdbQfTCGyzzHCq5Dxyk6vmGAdjAEK4,13462
|
|
7
|
+
figkit/language.py,sha256=tGuuaJepHepd7cdTMweDPOvZMUjpv-y5EyOmPvC5VnM,4938
|
|
8
|
+
figkit/manifest.py,sha256=WSwddxPqEU-J_THQAN0PJWVtYZUrQS3uriJ_hWr894Y,6800
|
|
9
|
+
figkit/preview.py,sha256=F7AFyyFOL323ULWTtkieil3z3_fjoc8Q2G7lPRIpQu4,3586
|
|
10
|
+
figkit/project.py,sha256=NzmIWysWt3LZb6WLlqseAc2e0vyB6LoBqoHE_SylgCw,6753
|
|
11
|
+
figkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
figkit/theme.py,sha256=CJHcNZ9S24h-K4Ru58MptInWzY1jgpxFHE3G1ud0cKc,20493
|
|
13
|
+
figkit/tokens.json,sha256=BbgxOlEOe9TB8TMV-ZopFKVLoxKQ_MNP65_J9XOsOsU,1732
|
|
14
|
+
figkit/tokens.schema.json,sha256=Camf3Ip9zZeQIHmdvWyC_1_O5YSDO7lTt9xMIs7X2lg,3715
|
|
15
|
+
figkit/fonts/BricolageGrotesque-Regular.ttf,sha256=3AquF6Liui0XpPBjlU-Wg-Q8WwC27Ve-XGDkKyCCknM,90540
|
|
16
|
+
figkit/fonts/BricolageGrotesque-SemiBold.ttf,sha256=2O7jXYkFziBjQv2dxt6ngky2gmnXm6LLalV50HMcVcI,90544
|
|
17
|
+
figkit/fonts/JetBrainsMono-Regular.ttf,sha256=y1cm3NU2g0e0IJUlfy38fFo0fxfw4vYwk2Sl7JDrafY,114920
|
|
18
|
+
figkit/fonts/JetBrainsMono-SemiBold.ttf,sha256=ewc1MH3REVJMqba04BVQKUavDW7kslFBtAPihRdpBzs,114932
|
|
19
|
+
figkit/fonts/OFL-BricolageGrotesque.txt,sha256=S1p9jzf1YCYhyKjXNYpqLnExfmwjHGYeFa7wJ10-B7o,4403
|
|
20
|
+
figkit/fonts/OFL-JetBrainsMono.txt,sha256=sv5eiYdZTp_9HSylKi9dc-uDNSQ4k8XWJUta1pJpWR0,4399
|
|
21
|
+
figurekit-0.5.1.dist-info/METADATA,sha256=KJ41UcEGNRDqZP6kh3lzHKQn2sPgM1oR8bKEEixQDos,19161
|
|
22
|
+
figurekit-0.5.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
23
|
+
figurekit-0.5.1.dist-info/entry_points.txt,sha256=1zPkhEisv9wrdxioEj9UKiFjv019BwAIeKv-aKLVgVw,43
|
|
24
|
+
figurekit-0.5.1.dist-info/licenses/LICENSE,sha256=UA30ih7jv0VkVxBUklIroBxUaprKr5InZzKPqCnYCv8,1069
|
|
25
|
+
figurekit-0.5.1.dist-info/licenses/src/figkit/fonts/OFL-BricolageGrotesque.txt,sha256=S1p9jzf1YCYhyKjXNYpqLnExfmwjHGYeFa7wJ10-B7o,4403
|
|
26
|
+
figurekit-0.5.1.dist-info/licenses/src/figkit/fonts/OFL-JetBrainsMono.txt,sha256=sv5eiYdZTp_9HSylKi9dc-uDNSQ4k8XWJUta1pJpWR0,4399
|
|
27
|
+
figurekit-0.5.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benny Botsch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2022 The Bricolage Grotesque Project Authors (https://github.com/ateliertriay/bricolage)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|