hedgehogs 0.0.1__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.
- hedgehogs-0.0.1/CHANGELOG.md +17 -0
- hedgehogs-0.0.1/LICENSE +22 -0
- hedgehogs-0.0.1/MANIFEST.in +6 -0
- hedgehogs-0.0.1/PKG-INFO +133 -0
- hedgehogs-0.0.1/README.md +103 -0
- hedgehogs-0.0.1/docs/README.md +12 -0
- hedgehogs-0.0.1/docs/api/README.md +33 -0
- hedgehogs-0.0.1/docs/api/figures.md +151 -0
- hedgehogs-0.0.1/docs/api/palettes.md +128 -0
- hedgehogs-0.0.1/docs/api/plots.md +146 -0
- hedgehogs-0.0.1/docs/api/tables.md +130 -0
- hedgehogs-0.0.1/docs/api/terminal.md +105 -0
- hedgehogs-0.0.1/docs/developer/architecture.md +87 -0
- hedgehogs-0.0.1/docs/developer/presentation.md +78 -0
- hedgehogs-0.0.1/docs/developer/release.md +30 -0
- hedgehogs-0.0.1/others/assets/icon.svg +1 -0
- hedgehogs-0.0.1/others/palettes/000000.svg +1 -0
- hedgehogs-0.0.1/others/palettes/0072b2.svg +1 -0
- hedgehogs-0.0.1/others/palettes/0077bb.svg +1 -0
- hedgehogs-0.0.1/others/palettes/009988.svg +1 -0
- hedgehogs-0.0.1/others/palettes/009e73.svg +1 -0
- hedgehogs-0.0.1/others/palettes/117733.svg +1 -0
- hedgehogs-0.0.1/others/palettes/228833.svg +1 -0
- hedgehogs-0.0.1/others/palettes/332288.svg +1 -0
- hedgehogs-0.0.1/others/palettes/33bbee.svg +1 -0
- hedgehogs-0.0.1/others/palettes/4477aa.svg +1 -0
- hedgehogs-0.0.1/others/palettes/44aa99.svg +1 -0
- hedgehogs-0.0.1/others/palettes/4e79a7.svg +1 -0
- hedgehogs-0.0.1/others/palettes/56b4e9.svg +1 -0
- hedgehogs-0.0.1/others/palettes/59a14f.svg +1 -0
- hedgehogs-0.0.1/others/palettes/648fff.svg +1 -0
- hedgehogs-0.0.1/others/palettes/66ccee.svg +1 -0
- hedgehogs-0.0.1/others/palettes/76b7b2.svg +1 -0
- hedgehogs-0.0.1/others/palettes/785ef0.svg +1 -0
- hedgehogs-0.0.1/others/palettes/882255.svg +1 -0
- hedgehogs-0.0.1/others/palettes/88ccee.svg +1 -0
- hedgehogs-0.0.1/others/palettes/999933.svg +1 -0
- hedgehogs-0.0.1/others/palettes/9c755f.svg +1 -0
- hedgehogs-0.0.1/others/palettes/aa3377.svg +1 -0
- hedgehogs-0.0.1/others/palettes/aa4499.svg +1 -0
- hedgehogs-0.0.1/others/palettes/b07aa1.svg +1 -0
- hedgehogs-0.0.1/others/palettes/bab0ac.svg +1 -0
- hedgehogs-0.0.1/others/palettes/bbbbbb.svg +1 -0
- hedgehogs-0.0.1/others/palettes/cc3311.svg +1 -0
- hedgehogs-0.0.1/others/palettes/cc6677.svg +1 -0
- hedgehogs-0.0.1/others/palettes/cc79a7.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ccbb44.svg +1 -0
- hedgehogs-0.0.1/others/palettes/d55e00.svg +1 -0
- hedgehogs-0.0.1/others/palettes/dc267f.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ddcc77.svg +1 -0
- hedgehogs-0.0.1/others/palettes/e15759.svg +1 -0
- hedgehogs-0.0.1/others/palettes/e69f00.svg +1 -0
- hedgehogs-0.0.1/others/palettes/edc948.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ee3377.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ee6677.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ee7733.svg +1 -0
- hedgehogs-0.0.1/others/palettes/f0e442.svg +1 -0
- hedgehogs-0.0.1/others/palettes/f28e2b.svg +1 -0
- hedgehogs-0.0.1/others/palettes/fe6100.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ff9da7.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ffb000.svg +1 -0
- hedgehogs-0.0.1/others/palettes/ibm.svg +1 -0
- hedgehogs-0.0.1/others/palettes/okabe-ito.svg +1 -0
- hedgehogs-0.0.1/others/palettes/paul-tol-bright.svg +1 -0
- hedgehogs-0.0.1/others/palettes/paul-tol-muted.svg +1 -0
- hedgehogs-0.0.1/others/palettes/paul-tol-vibrant.svg +1 -0
- hedgehogs-0.0.1/others/palettes/tableau10.svg +1 -0
- hedgehogs-0.0.1/pyproject.toml +74 -0
- hedgehogs-0.0.1/setup.cfg +4 -0
- hedgehogs-0.0.1/src/hedgehogs/__init__.py +66 -0
- hedgehogs-0.0.1/src/hedgehogs/core/__init__.py +1 -0
- hedgehogs-0.0.1/src/hedgehogs/core/constants.py +6 -0
- hedgehogs-0.0.1/src/hedgehogs/core/environment.py +8 -0
- hedgehogs-0.0.1/src/hedgehogs/core/info.py +15 -0
- hedgehogs-0.0.1/src/hedgehogs/core/palette.py +263 -0
- hedgehogs-0.0.1/src/hedgehogs/core/version.py +4 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/__init__.py +13 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/helpers.py +129 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/output.py +75 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/pairplot.py +275 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/presentation.py +294 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/rendering.py +691 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/style.py +311 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/tree.py +269 -0
- hedgehogs-0.0.1/src/hedgehogs/plots/typography.py +224 -0
- hedgehogs-0.0.1/src/hedgehogs/py.typed +1 -0
- hedgehogs-0.0.1/src/hedgehogs/tables/__init__.py +5 -0
- hedgehogs-0.0.1/src/hedgehogs/tables/table.py +310 -0
- hedgehogs-0.0.1/src/hedgehogs/terminal/__init__.py +6 -0
- hedgehogs-0.0.1/src/hedgehogs/terminal/output.py +61 -0
- hedgehogs-0.0.1/src/hedgehogs/terminal/progress.py +304 -0
- hedgehogs-0.0.1/src/hedgehogs.egg-info/PKG-INFO +133 -0
- hedgehogs-0.0.1/src/hedgehogs.egg-info/SOURCES.txt +114 -0
- hedgehogs-0.0.1/src/hedgehogs.egg-info/dependency_links.txt +1 -0
- hedgehogs-0.0.1/src/hedgehogs.egg-info/requires.txt +7 -0
- hedgehogs-0.0.1/src/hedgehogs.egg-info/top_level.txt +1 -0
- hedgehogs-0.0.1/tests/README.md +40 -0
- hedgehogs-0.0.1/tests/core/test_package.py +14 -0
- hedgehogs-0.0.1/tests/core/test_palette.py +44 -0
- hedgehogs-0.0.1/tests/core/test_public_api.py +109 -0
- hedgehogs-0.0.1/tests/plots/test_figure_scaling.py +672 -0
- hedgehogs-0.0.1/tests/plots/test_pairplot.py +188 -0
- hedgehogs-0.0.1/tests/plots/test_presentation.py +431 -0
- hedgehogs-0.0.1/tests/plots/test_style.py +194 -0
- hedgehogs-0.0.1/tests/plots/test_tree.py +164 -0
- hedgehogs-0.0.1/tests/tables/test_table.py +406 -0
- hedgehogs-0.0.1/tests/terminal/test_progress.py +66 -0
- hedgehogs-0.0.1/tests/terminal/test_terminal.py +22 -0
- hedgehogs-0.0.1/tools/docs/render_palette_swatches.py +33 -0
- hedgehogs-0.0.1/tools/render_figures.py +95 -0
- hedgehogs-0.0.1/tools/render_pairplots.py +28 -0
- hedgehogs-0.0.1/tools/render_presentation.py +51 -0
- hedgehogs-0.0.1/tools/render_trees.py +37 -0
- hedgehogs-0.0.1/tutorials/cli.ipynb +121 -0
- hedgehogs-0.0.1/tutorials/plots.ipynb +449 -0
- hedgehogs-0.0.1/tutorials/tables.ipynb +325 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.1 — 8 October 2026
|
|
4
|
+
|
|
5
|
+
Initial Hedgehogs development release, adapted from Onsaemiro. Includes figure styling and finishing, native tree and pair plots, notebook and terminal tables, palettes and progress reporting.
|
|
6
|
+
|
|
7
|
+
`plots.save()` accepts a complete filename such as `figure.pdf`, or an extensionless path with `formats` for multiple outputs. Conflicting format selections raise `ValueError`.
|
|
8
|
+
|
|
9
|
+
Figure finishing refines default typography and numeric tick density while preserving explicit font options, custom ticks and plotted values.
|
|
10
|
+
|
|
11
|
+
Progress iteration uses `Progress(iterable, ...)`; delays use the standard `time.sleep()`. API references are grouped under `docs/api`.
|
|
12
|
+
|
|
13
|
+
Figure saving uses `plots.save(filename, fig=None, ...)`; the former top-level `export_figure()` is removed. `Table.to_dataframe()` exports formatted rows to an optional pandas or Polars backend.
|
|
14
|
+
|
|
15
|
+
Default outlines use bounded panel-area scaling independently of typography, retaining their weight across aspect ratios and preserving small marker faces.
|
|
16
|
+
|
|
17
|
+
Default data lines follow the same stroke scaling. Automatic legend placement searches inside the axes; explicit positions and external anchors are retained.
|
hedgehogs-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PentagonToy
|
|
4
|
+
Copyright (c) 2026 Hanseul Kang
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
hedgehogs-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hedgehogs
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Scientific presentation utilities for figures, notebooks, and terminals
|
|
5
|
+
Author-email: Hanseul Kang <hanseul.kang@aalto.fi>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/PentagonToy/Hedgehogs
|
|
8
|
+
Project-URL: Issues, https://github.com/PentagonToy/Hedgehogs/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/PentagonToy/Hedgehogs/blob/main/docs/README.md
|
|
10
|
+
Project-URL: Changelog, https://github.com/PentagonToy/Hedgehogs/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: matplotlib,scientific-visualisation,publication,plotting,jupyter
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: matplotlib>=3.6
|
|
24
|
+
Requires-Dist: ipython>=8
|
|
25
|
+
Requires-Dist: rich>=13.7
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Hedgehogs
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/PentagonToy/Hedgehogs/blob/main/others/assets/icon.svg">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/PentagonToy/Hedgehogs/main/others/assets/icon.svg?revision=b28effc0f83b" alt="Hedgehogs logo and wordmark, with orange and blue accents" width="270">
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
**Scientific figures and reports for Python.**
|
|
40
|
+
|
|
41
|
+
Hedgehogs prepares Matplotlib figures and presents tables, progress and status messages in notebooks and terminals.
|
|
42
|
+
|
|
43
|
+
- Journal-oriented figure presets for single- and double-column layouts.
|
|
44
|
+
- Colour-blind-friendly palettes, including Okabe–Ito and Paul Tol schemes.
|
|
45
|
+
- Consistent figure dimensions across local and remote notebook display and export.
|
|
46
|
+
- Clear tables, status messages and progress bars in notebooks, terminals and redirected logs.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
Requires **Python 3.10+**. Install from a source checkout:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/PentagonToy/Hedgehogs.git
|
|
54
|
+
cd Hedgehogs
|
|
55
|
+
python -m pip install -e .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage Example
|
|
59
|
+
|
|
60
|
+
### Figures
|
|
61
|
+
|
|
62
|
+
Choose the journal dimensions first, then draw with Matplotlib. The style supplies typography, line widths, marker sizes and outlines; finishing measures the complete figure and adjusts supported legend and bar-label placement.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import numpy as np
|
|
66
|
+
import matplotlib.pyplot as plt
|
|
67
|
+
import hedgehogs as hdg
|
|
68
|
+
|
|
69
|
+
fig_x, fig_y = hdg.figsize(name="science", column="single")
|
|
70
|
+
palette = hdg.get_palette("okabe-ito")
|
|
71
|
+
hdg.set_style(figure_size=(fig_x, fig_y), palette="okabe-ito")
|
|
72
|
+
|
|
73
|
+
x = np.linspace(0, 1, 25)
|
|
74
|
+
y = 2 * x + 0.1 * np.sin(20 * x)
|
|
75
|
+
fitted = np.polyval(np.polyfit(x, y, 1), x)
|
|
76
|
+
|
|
77
|
+
fig, ax = plt.subplots(figsize=(fig_x, fig_y))
|
|
78
|
+
ax.scatter(x, y, color=palette["blue"], label="Data")
|
|
79
|
+
ax.plot(x, fitted, color=palette["black"], label="Linear fit")
|
|
80
|
+
ax.set(xlabel="x", ylabel="y")
|
|
81
|
+
ax.legend()
|
|
82
|
+
|
|
83
|
+
hdg.plots.save("linear_fit.pdf", bbox_inches=None)
|
|
84
|
+
hdg.plots.show()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`figsize()` returns width and height in inches for `science`, `nature`, `ieee` or `aps`, with `single` or `double` columns. Presets provide starting dimensions; check the target journal's author instructions. Use an extensionless path with `formats=("pdf", "png")` for multiple outputs. Matplotlib arguments and artist properties remain editable.
|
|
88
|
+
|
|
89
|
+
[Tree diagrams and pairplots](https://github.com/PentagonToy/Hedgehogs/blob/main/docs/api/plots.md) also return editable Matplotlib objects. Keep text readable at the final document width; select fewer variables or split crowded figures before reducing font size.
|
|
90
|
+
|
|
91
|
+
### Tables
|
|
92
|
+
|
|
93
|
+
Display the same table in a notebook or terminal, then export its formatted values to CSV and LaTeX.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
table = hdg.Table("Model comparison", columns=["Case", "RMSE"], formatters={"RMSE": ".3f"})
|
|
97
|
+
table.add_row("baseline", 0.0412)
|
|
98
|
+
table.add_row("model", 0.0184)
|
|
99
|
+
table.show()
|
|
100
|
+
table.to_csv("errors.csv")
|
|
101
|
+
table.to_latex("errors.tex", caption="Model errors", label="tab:errors")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`Table.from_dataframe()` accepts existing **pandas** and **Polars** DataFrames. The LaTeX output requires `booktabs`. Tables or accompanying data provide precise values; figures communicate patterns and comparisons.
|
|
105
|
+
|
|
106
|
+
### Progress
|
|
107
|
+
|
|
108
|
+
Wrap an iterable with `Progress` to report progress in notebooks, terminals and redirected logs.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import time
|
|
112
|
+
|
|
113
|
+
for step in hdg.Progress(range(20), desc="Processing"):
|
|
114
|
+
time.sleep(0.05)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
For manually advanced work, `Progress` supports `update()`, metric reporting through `set()` and a context manager. See the [progress reference](https://github.com/PentagonToy/Hedgehogs/blob/main/docs/api/terminal.md#progress).
|
|
118
|
+
|
|
119
|
+
### Terminal output
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
hdg.echo("Reading data", tone="info")
|
|
123
|
+
hdg.echo("Run completed", tone="success")
|
|
124
|
+
hdg.rule("Summary")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Terminal output includes colour where supported. Redirected output remains plain; `NO_COLOR` and `TERM=dumb` disable colour.
|
|
128
|
+
|
|
129
|
+
## Documentation and tutorials
|
|
130
|
+
|
|
131
|
+
Use the [documentation roadmap](https://github.com/PentagonToy/Hedgehogs/blob/main/docs/README.md) for guides, API references and developer documentation. Runnable tutorials cover [plots](https://github.com/PentagonToy/Hedgehogs/blob/main/tutorials/plots.ipynb), [tables](https://github.com/PentagonToy/Hedgehogs/blob/main/tutorials/tables.ipynb), and [CLI output](https://github.com/PentagonToy/Hedgehogs/blob/main/tutorials/cli.ipynb).
|
|
132
|
+
|
|
133
|
+
Existing Onsaemiro code can replace its import with `import hedgehogs as hdg`. Wrap iterable work with `hdg.Progress(iterable, ...)` and use the standard `time.sleep()` for delays.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Hedgehogs
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/PentagonToy/Hedgehogs/blob/main/others/assets/icon.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/PentagonToy/Hedgehogs/main/others/assets/icon.svg?revision=b28effc0f83b" alt="Hedgehogs logo and wordmark, with orange and blue accents" width="270">
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
**Scientific figures and reports for Python.**
|
|
10
|
+
|
|
11
|
+
Hedgehogs prepares Matplotlib figures and presents tables, progress and status messages in notebooks and terminals.
|
|
12
|
+
|
|
13
|
+
- Journal-oriented figure presets for single- and double-column layouts.
|
|
14
|
+
- Colour-blind-friendly palettes, including Okabe–Ito and Paul Tol schemes.
|
|
15
|
+
- Consistent figure dimensions across local and remote notebook display and export.
|
|
16
|
+
- Clear tables, status messages and progress bars in notebooks, terminals and redirected logs.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Requires **Python 3.10+**. Install from a source checkout:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/PentagonToy/Hedgehogs.git
|
|
24
|
+
cd Hedgehogs
|
|
25
|
+
python -m pip install -e .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage Example
|
|
29
|
+
|
|
30
|
+
### Figures
|
|
31
|
+
|
|
32
|
+
Choose the journal dimensions first, then draw with Matplotlib. The style supplies typography, line widths, marker sizes and outlines; finishing measures the complete figure and adjusts supported legend and bar-label placement.
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import numpy as np
|
|
36
|
+
import matplotlib.pyplot as plt
|
|
37
|
+
import hedgehogs as hdg
|
|
38
|
+
|
|
39
|
+
fig_x, fig_y = hdg.figsize(name="science", column="single")
|
|
40
|
+
palette = hdg.get_palette("okabe-ito")
|
|
41
|
+
hdg.set_style(figure_size=(fig_x, fig_y), palette="okabe-ito")
|
|
42
|
+
|
|
43
|
+
x = np.linspace(0, 1, 25)
|
|
44
|
+
y = 2 * x + 0.1 * np.sin(20 * x)
|
|
45
|
+
fitted = np.polyval(np.polyfit(x, y, 1), x)
|
|
46
|
+
|
|
47
|
+
fig, ax = plt.subplots(figsize=(fig_x, fig_y))
|
|
48
|
+
ax.scatter(x, y, color=palette["blue"], label="Data")
|
|
49
|
+
ax.plot(x, fitted, color=palette["black"], label="Linear fit")
|
|
50
|
+
ax.set(xlabel="x", ylabel="y")
|
|
51
|
+
ax.legend()
|
|
52
|
+
|
|
53
|
+
hdg.plots.save("linear_fit.pdf", bbox_inches=None)
|
|
54
|
+
hdg.plots.show()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`figsize()` returns width and height in inches for `science`, `nature`, `ieee` or `aps`, with `single` or `double` columns. Presets provide starting dimensions; check the target journal's author instructions. Use an extensionless path with `formats=("pdf", "png")` for multiple outputs. Matplotlib arguments and artist properties remain editable.
|
|
58
|
+
|
|
59
|
+
[Tree diagrams and pairplots](https://github.com/PentagonToy/Hedgehogs/blob/main/docs/api/plots.md) also return editable Matplotlib objects. Keep text readable at the final document width; select fewer variables or split crowded figures before reducing font size.
|
|
60
|
+
|
|
61
|
+
### Tables
|
|
62
|
+
|
|
63
|
+
Display the same table in a notebook or terminal, then export its formatted values to CSV and LaTeX.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
table = hdg.Table("Model comparison", columns=["Case", "RMSE"], formatters={"RMSE": ".3f"})
|
|
67
|
+
table.add_row("baseline", 0.0412)
|
|
68
|
+
table.add_row("model", 0.0184)
|
|
69
|
+
table.show()
|
|
70
|
+
table.to_csv("errors.csv")
|
|
71
|
+
table.to_latex("errors.tex", caption="Model errors", label="tab:errors")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`Table.from_dataframe()` accepts existing **pandas** and **Polars** DataFrames. The LaTeX output requires `booktabs`. Tables or accompanying data provide precise values; figures communicate patterns and comparisons.
|
|
75
|
+
|
|
76
|
+
### Progress
|
|
77
|
+
|
|
78
|
+
Wrap an iterable with `Progress` to report progress in notebooks, terminals and redirected logs.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import time
|
|
82
|
+
|
|
83
|
+
for step in hdg.Progress(range(20), desc="Processing"):
|
|
84
|
+
time.sleep(0.05)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For manually advanced work, `Progress` supports `update()`, metric reporting through `set()` and a context manager. See the [progress reference](https://github.com/PentagonToy/Hedgehogs/blob/main/docs/api/terminal.md#progress).
|
|
88
|
+
|
|
89
|
+
### Terminal output
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
hdg.echo("Reading data", tone="info")
|
|
93
|
+
hdg.echo("Run completed", tone="success")
|
|
94
|
+
hdg.rule("Summary")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Terminal output includes colour where supported. Redirected output remains plain; `NO_COLOR` and `TERM=dumb` disable colour.
|
|
98
|
+
|
|
99
|
+
## Documentation and tutorials
|
|
100
|
+
|
|
101
|
+
Use the [documentation roadmap](https://github.com/PentagonToy/Hedgehogs/blob/main/docs/README.md) for guides, API references and developer documentation. Runnable tutorials cover [plots](https://github.com/PentagonToy/Hedgehogs/blob/main/tutorials/plots.ipynb), [tables](https://github.com/PentagonToy/Hedgehogs/blob/main/tutorials/tables.ipynb), and [CLI output](https://github.com/PentagonToy/Hedgehogs/blob/main/tutorials/cli.ipynb).
|
|
102
|
+
|
|
103
|
+
Existing Onsaemiro code can replace its import with `import hedgehogs as hdg`. Wrap iterable work with `hdg.Progress(iterable, ...)` and use the standard `time.sleep()` for delays.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Hedgehogs documentation
|
|
2
|
+
|
|
3
|
+
The [project README](../README.md) introduces installation and usage; notebooks in [tutorials](../tutorials) contain worked examples.
|
|
4
|
+
|
|
5
|
+
| Area | Purpose |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| [API reference](api/README.md) | Public names, signatures, parameters, returns and examples |
|
|
8
|
+
| [Presentation rules](developer/presentation.md) | Typography, outlines, sizing and final publication proportions |
|
|
9
|
+
| [Implementation ownership](developer/architecture.md) | Module responsibilities and rendering lifecycle |
|
|
10
|
+
| [Release preparation](developer/release.md) | Build, verify and publish distributions |
|
|
11
|
+
|
|
12
|
+
Each topic has one reference. Palette previews and journal dimensions are included in the API pages rather than separate guides.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Python API reference
|
|
2
|
+
|
|
3
|
+
Hedgehogs configures scientific figures and presents results in notebooks and terminals. Examples use `import hedgehogs as hdg`; Matplotlib retains ownership of figures and artists.
|
|
4
|
+
|
|
5
|
+
## Public namespace
|
|
6
|
+
|
|
7
|
+
| Group | Public names | Purpose |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| Figures | `set_style`, `reset_style`, `journal_preset`, `set_journal_style`, `figsize`, `subplots` | Configure and create figures |
|
|
10
|
+
| Figure helpers | `finalize`, `annotate_panels`, `style_colorbar`, `apply_grid`, `enable_minor_ticks` | Adjust existing axes and panels |
|
|
11
|
+
| Specialised plots | `plots.tree`, `plots.pairplot`, `plots.show`, `plots.save` | Draw, finish and save figures |
|
|
12
|
+
| Palettes | `Palette`, `get_palette`, `build_color_map`, `build_style_map`, `register_palette`, `save_palette`, `load_palette` | Select and map colours |
|
|
13
|
+
| Tables | `Table` | Format, display and export rows |
|
|
14
|
+
| Terminal output | `Progress`, `echo`, `rule`, `info` | Report activity and inspect package versions |
|
|
15
|
+
| Numerical support | `EPS` | Read floating-point machine epsilon |
|
|
16
|
+
|
|
17
|
+
## Reference map
|
|
18
|
+
|
|
19
|
+
| Task | Reference | Main API |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| Style and size figures | [Figures](figures.md) | `set_style`, `figsize`, `subplots` |
|
|
22
|
+
| Draw, finish and save plots | [Plots](plots.md) | `plots.tree`, `plots.pairplot`, `plots.show`, `plots.save` |
|
|
23
|
+
| Select colours or define series styles | [Palettes](palettes.md) | `get_palette`, `build_style_map`, `register_palette` |
|
|
24
|
+
| Format and export results | [Tables](tables.md) | `Table` |
|
|
25
|
+
| Report progress and status | [Terminal output](terminal.md) | `Progress`, `echo`, `rule` |
|
|
26
|
+
|
|
27
|
+
## Reference conventions
|
|
28
|
+
|
|
29
|
+
API indices summarise purpose and return values. Signatures show keyword-only options after `*`; parameter tables describe defaults and constraints. `None` requests the documented inference or disables an optional behaviour. Paths accept `str` and `os.PathLike`.
|
|
30
|
+
|
|
31
|
+
Figures and artists remain editable. `Table` and `Progress` update their state in place. Figure style affects global Matplotlib settings until `reset_style()` restores them. `EPS` equals `sys.float_info.epsilon`; it supplies a floating-point constant rather than a universal numerical tolerance.
|
|
32
|
+
|
|
33
|
+
Read the [documentation roadmap](../README.md) for guides and tutorials, and [implementation ownership](../developer/architecture.md) for lifecycle and extension rules.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Figure API
|
|
2
|
+
|
|
3
|
+
Examples assume `import hedgehogs as hdg`.
|
|
4
|
+
|
|
5
|
+
## API index
|
|
6
|
+
|
|
7
|
+
| API | Purpose | Returns |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `hdg.set_style(...)` | Configure global presentation defaults | `None` |
|
|
10
|
+
| `hdg.reset_style()` | Restore Matplotlib defaults and methods | `None` |
|
|
11
|
+
| `hdg.journal_preset(...)` | Read a journal preset | `dict` |
|
|
12
|
+
| `hdg.set_journal_style(...)` | Apply a journal preset | `dict` |
|
|
13
|
+
| `hdg.figsize(...)` | Read physical figure dimensions | `(width, height)` |
|
|
14
|
+
| `hdg.subplots(...)` | Create a figure and axes | `(Figure, axes)` |
|
|
15
|
+
| `hdg.finalize(...)` | Adjust existing axes and legend styling | `None` |
|
|
16
|
+
| `hdg.annotate_panels(...)` | Label panels | `None` |
|
|
17
|
+
| `hdg.style_colorbar(...)` | Style a colour bar | `None` |
|
|
18
|
+
| `hdg.apply_grid(...)` | Add a major grid | `None` |
|
|
19
|
+
| `hdg.enable_minor_ticks(...)` | Add minor tick locators | `None` |
|
|
20
|
+
|
|
21
|
+
## Styling and layout
|
|
22
|
+
|
|
23
|
+
### `set_style`
|
|
24
|
+
|
|
25
|
+
Apply global Matplotlib presentation defaults and enable proportional sizing for newly created figures.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
hdg.set_style(
|
|
29
|
+
base_fontsize=10.5, linewidth=1.1, figure_size=(2.24, 2.20),
|
|
30
|
+
subplot=None, use_tex=False, auto_scale=False,
|
|
31
|
+
scale_exponent=0.5, palette="okabe-ito",
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Default | Constraint or meaning |
|
|
36
|
+
| --- | --- | --- | --- |
|
|
37
|
+
| `base_fontsize` | `float` | `10.5` | Body-text size in points before optional width scaling |
|
|
38
|
+
| `linewidth` | `float` | `1.1` | Base stroke width before optional scaling |
|
|
39
|
+
| `figure_size` | `tuple[float, float]` | `(2.24, 2.20)` | Reference canvas width and height in inches |
|
|
40
|
+
| `subplot` | mapping or `None` | `None` | Overrides fixed `left`, `bottom`, `right`, or `top` fractions |
|
|
41
|
+
| `use_tex` | `bool` | `False` | Enable Matplotlib TeX rendering |
|
|
42
|
+
| `auto_scale` | `bool` | `False` | Apply the initial width-based calculation; automatic resizing operates independently |
|
|
43
|
+
| `scale_exponent` | `float` | `0.5` | Width-scaling exponent |
|
|
44
|
+
| `palette` | `str` | `"okabe-ito"` | Registered palette name |
|
|
45
|
+
|
|
46
|
+
Returns `None`. Filled markers receive black outlines unless an edge colour is supplied; unfilled markers such as `"x"` use a single stroke colour. The style applies to new Matplotlib figures. Single panels scale relative to `figure_size`; subplot grids retain configured point sizes. See [Presentation proportions](../developer/presentation.md) for the scaling rules.
|
|
47
|
+
|
|
48
|
+
### `reset_style`
|
|
49
|
+
|
|
50
|
+
Stop automatic figure sizing and restore Matplotlib defaults.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
hdg.reset_style() -> None
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Returns `None`.
|
|
57
|
+
|
|
58
|
+
### `journal_preset`, `set_journal_style`, and `figsize`
|
|
59
|
+
|
|
60
|
+
Read or apply a named journal preset.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
hdg.journal_preset(name="science", column="single") -> dict[str, object]
|
|
64
|
+
hdg.set_journal_style(name="science", column="single", **overrides) -> dict[str, object]
|
|
65
|
+
hdg.figsize(name="science", column="single") -> tuple[float, float]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Supported journal names are `nature`, `science`, `ieee`, and `aps`; supported column widths are `single` and `double`. Journal typography uses stable point sizes at both column widths. `journal_preset()` returns a new dictionary containing `figure_size`, `base_fontsize`, and `linewidth`; `set_journal_style()` applies and returns those options with any `set_style()` overrides. `figsize()` returns dimensions in inches. Unknown journal names or column selections raise `ValueError`.
|
|
69
|
+
|
|
70
|
+
| Preset | Typical use | Single-column width | Double-column width |
|
|
71
|
+
| --- | --- | ---: | ---: |
|
|
72
|
+
| `nature` | Nature-family starting point | 3.50 in | 7.20 in |
|
|
73
|
+
| `science` | Science-family starting point | 2.24 in | 4.76 in |
|
|
74
|
+
| `ieee` | IEEE two-column papers | 3.50 in | 7.16 in |
|
|
75
|
+
| `aps` | APS journals | 3.40 in | 7.00 in |
|
|
76
|
+
|
|
77
|
+
| Parameter | Type | Default | Allowed values |
|
|
78
|
+
| --- | --- | --- | --- |
|
|
79
|
+
| `name` | `str` | `"science"` | `science`, `nature`, `ieee`, or `aps` |
|
|
80
|
+
| `column` | `str` | `"single"` | `single` or `double` |
|
|
81
|
+
| `**overrides` | keyword arguments | Empty | `set_style()` options; accepted by `set_journal_style()` only |
|
|
82
|
+
|
|
83
|
+
### `subplots`
|
|
84
|
+
|
|
85
|
+
Create a Matplotlib figure and its subplot axes.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
hdg.subplots(
|
|
89
|
+
nrows=1, ncols=1, *, figsize=None, journal=None, column="single",
|
|
90
|
+
subplot=None, gridspec_kw=None, widths=None, heights=None,
|
|
91
|
+
sharex=False, sharey=False, squeeze=True, layout=None, **ax_kw,
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Create ordinary Matplotlib objects. `widths` and `heights` are concise forms of GridSpec's `width_ratios` and `height_ratios`; do not supply both forms for the same dimension.
|
|
96
|
+
|
|
97
|
+
| Parameter | Default | Meaning |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `nrows`, `ncols` | `1`, `1` | Subplot grid dimensions |
|
|
100
|
+
| `figsize` | `None` | Explicit physical size in inches |
|
|
101
|
+
| `journal`, `column` | `None`, `"single"` | Optional journal-derived size |
|
|
102
|
+
| `subplot` | `None` | Fixed margin overrides |
|
|
103
|
+
| `gridspec_kw` | `None` | Matplotlib GridSpec options |
|
|
104
|
+
| `widths`, `heights` | `None` | Concise panel-ratio lists |
|
|
105
|
+
| `sharex`, `sharey` | `False` | Matplotlib shared-axis configuration |
|
|
106
|
+
| `squeeze` | `True` | Apply Matplotlib axes squeezing |
|
|
107
|
+
| `layout` | `None` | Matplotlib layout engine name |
|
|
108
|
+
| `**ax_kw` | Empty | Axes constructor options, passed as Matplotlib `subplot_kw` |
|
|
109
|
+
|
|
110
|
+
Returns `(fig, axes)`; axes shape follows `nrows`, `ncols`, and `squeeze`. Combining `figsize` with `journal`, or a ratio alias with its matching GridSpec key, raises `ValueError`.
|
|
111
|
+
|
|
112
|
+
For colour bars and nested axes, select `layout="constrained"`. Use `ax.set_box_aspect(1)` for a square plotting box.
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
fig, axes = hdg.subplots(2, 2, layout="constrained")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Figure finishing helpers
|
|
119
|
+
|
|
120
|
+
Adjust existing axes and colour bars without changing the plotted data.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
hdg.finalize(ax=None, fix_origin=True, keep="x", grid=False, minor_ticks=False)
|
|
124
|
+
hdg.annotate_panels(axes, labels=None, loc="upper left", offset=None, fontsize=None, fontweight="bold")
|
|
125
|
+
hdg.style_colorbar(cb, label=None)
|
|
126
|
+
hdg.apply_grid(ax=None, axis="both")
|
|
127
|
+
hdg.enable_minor_ticks(ax=None, x=True, y=True)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
| Helper | Parameters and defaults | Behaviour |
|
|
131
|
+
| --- | --- | --- |
|
|
132
|
+
| `finalize()` | `ax=None` selects current axes; also accepts an axes collection; `fix_origin=True`, `keep="x"`, `grid=False`, `minor_ticks=False` | Suppress one zero tick label when both ranges include zero, style existing legend frames, and optionally add grids or minor ticks |
|
|
133
|
+
| `annotate_panels()` | Required `axes`; `labels=None` generates `(a)`, `(b)`, …; `loc="upper left"`; `offset=None`; `fontsize=None` uses the current font size; `fontweight="bold"` | Place labels in axes coordinates; `offset=(x, y)` overrides placement, and `loc` selects left or right alignment |
|
|
134
|
+
| `style_colorbar()` | Required `cb`; `label=None` preserves the existing label | Apply configured outline and tick styling |
|
|
135
|
+
| `apply_grid()` | `ax=None` selects current axes; `axis="both"` accepts `x`, `y`, or `both` | Add a dotted major grid beneath the plotted data |
|
|
136
|
+
| `enable_minor_ticks()` | `ax=None` selects current axes; `x=True`, `y=True` | Install automatic minor locators for linear axes |
|
|
137
|
+
|
|
138
|
+
All five helpers return `None`. `finalize()` styles an existing legend; it does not create one. With `keep="x"`, the y-axis zero label is suppressed; use `keep="y"` to retain the y-axis zero label. Supply one custom panel label per axes because labels and axes are paired with `zip()`.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
ax.legend()
|
|
142
|
+
hdg.finalize(ax, grid=True)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Palettes
|
|
146
|
+
|
|
147
|
+
See [Palettes and series styles](palettes.md) for colour selection, series mapping and custom palette APIs.
|
|
148
|
+
|
|
149
|
+
## Specialised plots
|
|
150
|
+
|
|
151
|
+
See the [tree and pairplot reference](plots.md) for `hdg.plots.tree()` and `hdg.plots.pairplot()`.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Palette API
|
|
2
|
+
|
|
3
|
+
Examples assume `import hedgehogs as hdg`.
|
|
4
|
+
|
|
5
|
+
## API index
|
|
6
|
+
|
|
7
|
+
| API | Purpose | Returns |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `hdg.Palette(...)` | Hold named, ordered colours | `Palette` |
|
|
10
|
+
| `hdg.get_palette(...)` | Select a registered palette | `Palette` |
|
|
11
|
+
| `hdg.build_color_map(...)` | Assign colours to labels | `dict` |
|
|
12
|
+
| `hdg.build_style_map(...)` | Assign colour, marker and line styles | `dict` |
|
|
13
|
+
| `hdg.register_palette(...)` | Register validated colours | `Palette` |
|
|
14
|
+
| `hdg.save_palette(...)` | Write a palette to JSON | `Path` |
|
|
15
|
+
| `hdg.load_palette(...)` | Read and register JSON colours | `Palette` |
|
|
16
|
+
|
|
17
|
+
## Built-in palettes
|
|
18
|
+
|
|
19
|
+
Hedgehogs provides six categorical palettes; Okabe–Ito is the default. Swatches follow the exact package order, from left to right. The summary lists HEX values in the same order; indices start at zero.
|
|
20
|
+
|
|
21
|
+
| Palette | Colours | Preview | HEX values in index order |
|
|
22
|
+
| --- | ---: | --- | --- |
|
|
23
|
+
| `okabe-ito` | 8 |  | `#0072B2` `#E69F00` `#D55E00`<br>`#009E73` `#56B4E9` `#F0E442`<br>`#CC79A7` `#000000` |
|
|
24
|
+
| `tableau10` | 10 |  | `#4E79A7` `#F28E2B` `#E15759`<br>`#76B7B2` `#59A14F` `#EDC948`<br>`#B07AA1` `#FF9DA7` `#9C755F`<br>`#BAB0AC` |
|
|
25
|
+
| `paul-tol-vibrant` | 7 |  | `#0077BB` `#33BBEE` `#009988`<br>`#EE7733` `#CC3311` `#EE3377`<br>`#BBBBBB` |
|
|
26
|
+
| `paul-tol-bright` | 7 |  | `#4477AA` `#EE6677` `#228833`<br>`#CCBB44` `#66CCEE` `#AA3377`<br>`#BBBBBB` |
|
|
27
|
+
| `paul-tol-muted` | 9 |  | `#332288` `#88CCEE` `#44AA99`<br>`#117733` `#999933` `#DDCC77`<br>`#CC6677` `#882255` `#AA4499` |
|
|
28
|
+
| `ibm` | 5 |  | `#648FFF` `#785EF0` `#DC267F`<br>`#FE6100` `#FFB000` |
|
|
29
|
+
|
|
30
|
+
Colour names belong to each palette; the same name can have different HEX values across palettes. These are discrete series colours. Select a Matplotlib colormap separately for continuous fields. Combine colours with markers or line styles for greyscale reproduction.
|
|
31
|
+
|
|
32
|
+
## Select colours
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
palette = hdg.get_palette("okabe-ito")
|
|
36
|
+
ax.scatter(x, y, color=palette["blue"])
|
|
37
|
+
ax.plot(x, prediction, color=palette[1])
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`Palette` supports colour names, integer indices and slices. Integer indices cycle through the available colours; slices return colour lists. Available names depend on the selected palette. `len(palette)` reports the colour count; `keys()`, `values()` and `items()` expose names, colours and name–colour pairs. Built-in colour-name lookup ignores case. An unknown colour name raises `KeyError`.
|
|
41
|
+
|
|
42
|
+
Apply a palette to the global figure style with `hdg.set_style(palette="okabe-ito")`. For a pairplot, `hdg.plots.pairplot(data, hue="species", palette="tableau10")` selects its palette explicitly.
|
|
43
|
+
|
|
44
|
+
For the default palette, `palette[0]` and `palette["blue"]` both return `"#0072B2"`; `palette[8]` repeats the first colour. `palette[:3]` returns a list of the first three colours, while `hdg.get_palette("okabe-ito", n=3)` returns a three-colour `Palette`.
|
|
45
|
+
|
|
46
|
+
## Assign series styles
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
styles = hdg.build_style_map(["baseline", "model"])
|
|
50
|
+
ax.plot(x, baseline, label="Baseline", **styles["baseline"])
|
|
51
|
+
ax.plot(x, prediction, label="Model", **styles["model"])
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`build_color_map()` assigns colours alone. `build_style_map()` combines colours, markers and line styles for Matplotlib lines. Both functions retain the first occurrence of each label. Their `palette` argument defaults to Okabe–Ito independently of the active figure style; pass it explicitly for another palette. Colours repeat when labels outnumber colours. Line styles cycle through `-`, `--`, `-.` and `:`; markers cycle through `o`, `s`, `^`, `D`, `v`, `P` and `X`. These cycles can eventually repeat complete style combinations.
|
|
55
|
+
|
|
56
|
+
## Register and save
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
hdg.register_palette("models", {"baseline": "#0072B2", "model": "#D55E00"})
|
|
60
|
+
hdg.save_palette("models", "models.json")
|
|
61
|
+
hdg.load_palette("models.json", name="imported-models")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Registration lasts for the current Python process. Mapping order determines colour order. For custom colour names, prefer lowercase keys because lookup converts names to lowercase. An iterable of colours can instead supply `names=[...]`; omit `names` when passing a mapping. Save a palette as JSON to reuse it in another session.
|
|
65
|
+
|
|
66
|
+
`overwrite=True` replaces an existing registration. `load_palette()` uses an explicit `name`, then the stored JSON name, then the file stem. Saved JSON contains `name`, `names` and `colors`.
|
|
67
|
+
|
|
68
|
+
## Maintaining the colour tables
|
|
69
|
+
|
|
70
|
+
The tables mirror `core/palette.py`. After changing built-in colours, update their order and HEX values here, then regenerate swatches from the repository root:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
python tools/docs/render_palette_swatches.py others/palettes
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Palette objects
|
|
77
|
+
|
|
78
|
+
### `Palette`
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
hdg.Palette(names, colors)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`names` and `colors` are ordered iterables. The object supports integer and colour-name access, slicing, iteration, `len()`, `keys()`, `values()` and `items()`. Integer indices cycle through the available colours; slices return lists. An unknown colour name raises `KeyError`. Construct validated custom palettes through `register_palette()`.
|
|
85
|
+
|
|
86
|
+
### `get_palette`
|
|
87
|
+
|
|
88
|
+
Read a registered palette or select colours from an existing `Palette`.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
hdg.get_palette(palette="okabe-ito", n=None) -> Palette
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Return a palette with index, slice, and colour-name access. Built-in names include `okabe-ito`, `tableau10`, `paul-tol-vibrant`, `paul-tol-bright`, `paul-tol-muted`, and `ibm`.
|
|
95
|
+
|
|
96
|
+
| Parameter | Default | Meaning |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `palette` | `"okabe-ito"` | Registered name or `Palette` object |
|
|
99
|
+
| `n` | `None` | Positive integer limiting the number of colours; `None` retains all colours |
|
|
100
|
+
|
|
101
|
+
An invalid `n` raises `ValueError`. A limit larger than the palette returns all available colours. Palette names ignore case and accept partial family names such as `tol` or `tableau`; an unrecognised name emits `UserWarning` and falls back to Okabe–Ito. Prefer the exact names in the tables for reproducible selection.
|
|
102
|
+
|
|
103
|
+
## Series mapping
|
|
104
|
+
|
|
105
|
+
### `build_color_map` and `build_style_map`
|
|
106
|
+
|
|
107
|
+
Assign colours or combined visual styles to unique labels.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
hdg.build_color_map(labels, palette="okabe-ito") -> dict[object, str]
|
|
111
|
+
hdg.build_style_map(labels, palette="okabe-ito") -> dict[object, dict[str, str]]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`labels` is an iterable of hashable labels; `palette="okabe-ito"` accepts a registered name or `Palette`. Both functions preserve first-occurrence order. `build_style_map()` returns keyword dictionaries accepted by `Axes.plot()`.
|
|
115
|
+
|
|
116
|
+
## Custom palettes
|
|
117
|
+
|
|
118
|
+
Register palettes for the current process or transfer them through JSON.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
hdg.register_palette(name, colors, names=None, *, overwrite=False) -> Palette
|
|
122
|
+
hdg.save_palette(name, path) -> Path
|
|
123
|
+
hdg.load_palette(path, *, name=None, overwrite=False) -> Palette
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`colors` accepts a mapping of names to Matplotlib colours, or an iterable with optional `names`. Omitted names are generated as `color-1`, `color-2`, and so on. Empty palettes, invalid colours, duplicate colour names, and mismatched lengths raise `ValueError`. An existing palette requires `overwrite=True`. `save_palette()` writes JSON and returns its path; `load_palette()` reads the JSON, registers the palette, and returns a `Palette`.
|
|
127
|
+
|
|
128
|
+
See the [figure guide](figures.md) for styling and export.
|