figentra 0.1.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.
- figentra-0.1.0/LICENSE +21 -0
- figentra-0.1.0/PKG-INFO +111 -0
- figentra-0.1.0/README.md +91 -0
- figentra-0.1.0/pyproject.toml +28 -0
- figentra-0.1.0/setup.cfg +4 -0
- figentra-0.1.0/src/figentra/__init__.py +4 -0
- figentra-0.1.0/src/figentra/style.py +94 -0
- figentra-0.1.0/src/figentra.egg-info/PKG-INFO +111 -0
- figentra-0.1.0/src/figentra.egg-info/SOURCES.txt +11 -0
- figentra-0.1.0/src/figentra.egg-info/dependency_links.txt +1 -0
- figentra-0.1.0/src/figentra.egg-info/requires.txt +5 -0
- figentra-0.1.0/src/figentra.egg-info/top_level.txt +1 -0
- figentra-0.1.0/tests/test_style.py +35 -0
figentra-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 peterDataScientia
|
|
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.
|
figentra-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: figentra
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reproducible publication-ready scientific figure styling for Matplotlib
|
|
5
|
+
Author: peterDataScientia
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/peterDataScientia/figentra
|
|
8
|
+
Project-URL: Repository, https://github.com/peterDataScientia/figentra
|
|
9
|
+
Keywords: matplotlib,scientific-figures,publication,visualization
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: matplotlib>=3.6
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
18
|
+
Requires-Dist: build>=1; extra == "dev"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# Figentra
|
|
22
|
+
|
|
23
|
+
**Scientific figures. Consistently refined.**
|
|
24
|
+
|
|
25
|
+
Figentra is a lightweight Matplotlib styling package that reproduces the approved scientific figure settings from the `SNT100_MASTER_STYLE_1_TO_11.ipynb` research notebook.
|
|
26
|
+
|
|
27
|
+
**Figentra only changes presentation**. It does not modify data, fit models, smooth curves, normalize measurements or fabricate experimental results.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Install from the official GitHub repository today:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install git+https://github.com/peterDataScientia/figentra.git
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For local development:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/peterDataScientia/figentra.git
|
|
41
|
+
cd figentra
|
|
42
|
+
pip install -e ".[dev]"
|
|
43
|
+
pytest -q
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `pip install figentra` command will become available **after** the first successful PyPI release.
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import numpy as np
|
|
52
|
+
from figentra import new_figure, style_axes, legend_bold, save_figure
|
|
53
|
+
|
|
54
|
+
x = np.linspace(0, 120, 200)
|
|
55
|
+
y = np.exp(-x / 40) # illustration, not experimental data
|
|
56
|
+
|
|
57
|
+
fig, ax = new_figure()
|
|
58
|
+
ax.plot(x, y, lw=2, label="Example")
|
|
59
|
+
style_axes(ax, xlabel="Time [s]", ylabel="Response [a.u.]")
|
|
60
|
+
legend_bold(ax)
|
|
61
|
+
fig.subplots_adjust(left=.22, right=.92, bottom=.15, top=.81)
|
|
62
|
+
save_figure(fig, "Figure_01", output_dir="figures", close=True)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To style an existing Matplotlib figure:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from figentra import apply_style, style_axes
|
|
69
|
+
apply_style()
|
|
70
|
+
# draw with Matplotlib
|
|
71
|
+
style_axes(ax)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For temporary style changes without altering global configuration, use `with style_context():`.
|
|
75
|
+
|
|
76
|
+
## Approved visual standards
|
|
77
|
+
|
|
78
|
+
| Setting | Value |
|
|
79
|
+
|---|---|
|
|
80
|
+
| Canvas | 130 × 100 mm |
|
|
81
|
+
| Font | DejaVu Sans |
|
|
82
|
+
| Base font | 12 pt |
|
|
83
|
+
| Axis labels | 15 pt, bold |
|
|
84
|
+
| Tick labels | 12 pt, bold |
|
|
85
|
+
| Legend | 11 pt, bold, no frame |
|
|
86
|
+
| Axes | Left/bottom 2 pt; top/right hidden |
|
|
87
|
+
| Major ticks | 2 pt wide, 6 pt long, outward |
|
|
88
|
+
| Minor ticks and grid | Disabled |
|
|
89
|
+
| Background | White |
|
|
90
|
+
| Export formats | PNG, PDF and SVG |
|
|
91
|
+
| Raster export | 600 dpi |
|
|
92
|
+
| Vector font settings | PDF fonttype 42; SVG fonttype none |
|
|
93
|
+
|
|
94
|
+
Approved figure-specific colors, data scales, legend positioning and `subplots_adjust` are deliberately controlled by each plot rather than forced globally.
|
|
95
|
+
|
|
96
|
+
## Python API
|
|
97
|
+
|
|
98
|
+
- `apply_style()`: enable approved global Matplotlib styling
|
|
99
|
+
- `style_context()`: temporary styling context
|
|
100
|
+
- `new_figure(size_mm=None)`: create a 130 × 100 mm figure and axes
|
|
101
|
+
- `style_axes(ax, xlabel=None, ylabel=None)`: standardize labels, ticks, spines
|
|
102
|
+
- `legend_bold(ax, **kwargs)`: frame-free bold legend
|
|
103
|
+
- `save_figure(fig, stem, output_dir=".", formats=None, dpi=None, close=False)`: export all formats
|
|
104
|
+
|
|
105
|
+
## Release and PyPI
|
|
106
|
+
|
|
107
|
+
GitHub Actions tests Python 3.9, 3.11 and 3.13 on push/PR. A separate release workflow builds and publishes using PyPI Trusted Publishing. To activate public `pip install figentra`, configure a trusted publisher on PyPI using GitHub owner `peterDataScientia`, repository `figentra`, workflow `publish.yml`, environment `pypi`; create the GitHub `pypi` environment and publish a GitHub Release after CI passes. Publishing requires your own PyPI authorization; simply pushing this repository does not publish the package.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT — see [LICENSE](LICENSE).
|
figentra-0.1.0/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Figentra
|
|
2
|
+
|
|
3
|
+
**Scientific figures. Consistently refined.**
|
|
4
|
+
|
|
5
|
+
Figentra is a lightweight Matplotlib styling package that reproduces the approved scientific figure settings from the `SNT100_MASTER_STYLE_1_TO_11.ipynb` research notebook.
|
|
6
|
+
|
|
7
|
+
**Figentra only changes presentation**. It does not modify data, fit models, smooth curves, normalize measurements or fabricate experimental results.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install from the official GitHub repository today:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install git+https://github.com/peterDataScientia/figentra.git
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For local development:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/peterDataScientia/figentra.git
|
|
21
|
+
cd figentra
|
|
22
|
+
pip install -e ".[dev]"
|
|
23
|
+
pytest -q
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The `pip install figentra` command will become available **after** the first successful PyPI release.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import numpy as np
|
|
32
|
+
from figentra import new_figure, style_axes, legend_bold, save_figure
|
|
33
|
+
|
|
34
|
+
x = np.linspace(0, 120, 200)
|
|
35
|
+
y = np.exp(-x / 40) # illustration, not experimental data
|
|
36
|
+
|
|
37
|
+
fig, ax = new_figure()
|
|
38
|
+
ax.plot(x, y, lw=2, label="Example")
|
|
39
|
+
style_axes(ax, xlabel="Time [s]", ylabel="Response [a.u.]")
|
|
40
|
+
legend_bold(ax)
|
|
41
|
+
fig.subplots_adjust(left=.22, right=.92, bottom=.15, top=.81)
|
|
42
|
+
save_figure(fig, "Figure_01", output_dir="figures", close=True)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To style an existing Matplotlib figure:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from figentra import apply_style, style_axes
|
|
49
|
+
apply_style()
|
|
50
|
+
# draw with Matplotlib
|
|
51
|
+
style_axes(ax)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For temporary style changes without altering global configuration, use `with style_context():`.
|
|
55
|
+
|
|
56
|
+
## Approved visual standards
|
|
57
|
+
|
|
58
|
+
| Setting | Value |
|
|
59
|
+
|---|---|
|
|
60
|
+
| Canvas | 130 × 100 mm |
|
|
61
|
+
| Font | DejaVu Sans |
|
|
62
|
+
| Base font | 12 pt |
|
|
63
|
+
| Axis labels | 15 pt, bold |
|
|
64
|
+
| Tick labels | 12 pt, bold |
|
|
65
|
+
| Legend | 11 pt, bold, no frame |
|
|
66
|
+
| Axes | Left/bottom 2 pt; top/right hidden |
|
|
67
|
+
| Major ticks | 2 pt wide, 6 pt long, outward |
|
|
68
|
+
| Minor ticks and grid | Disabled |
|
|
69
|
+
| Background | White |
|
|
70
|
+
| Export formats | PNG, PDF and SVG |
|
|
71
|
+
| Raster export | 600 dpi |
|
|
72
|
+
| Vector font settings | PDF fonttype 42; SVG fonttype none |
|
|
73
|
+
|
|
74
|
+
Approved figure-specific colors, data scales, legend positioning and `subplots_adjust` are deliberately controlled by each plot rather than forced globally.
|
|
75
|
+
|
|
76
|
+
## Python API
|
|
77
|
+
|
|
78
|
+
- `apply_style()`: enable approved global Matplotlib styling
|
|
79
|
+
- `style_context()`: temporary styling context
|
|
80
|
+
- `new_figure(size_mm=None)`: create a 130 × 100 mm figure and axes
|
|
81
|
+
- `style_axes(ax, xlabel=None, ylabel=None)`: standardize labels, ticks, spines
|
|
82
|
+
- `legend_bold(ax, **kwargs)`: frame-free bold legend
|
|
83
|
+
- `save_figure(fig, stem, output_dir=".", formats=None, dpi=None, close=False)`: export all formats
|
|
84
|
+
|
|
85
|
+
## Release and PyPI
|
|
86
|
+
|
|
87
|
+
GitHub Actions tests Python 3.9, 3.11 and 3.13 on push/PR. A separate release workflow builds and publishes using PyPI Trusted Publishing. To activate public `pip install figentra`, configure a trusted publisher on PyPI using GitHub owner `peterDataScientia`, repository `figentra`, workflow `publish.yml`, environment `pypi`; create the GitHub `pypi` environment and publish a GitHub Release after CI passes. Publishing requires your own PyPI authorization; simply pushing this repository does not publish the package.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "figentra"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Reproducible publication-ready scientific figure styling for Matplotlib"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{name = "peterDataScientia"}]
|
|
13
|
+
keywords = ["matplotlib", "scientific-figures", "publication", "visualization"]
|
|
14
|
+
dependencies = ["matplotlib>=3.6"]
|
|
15
|
+
classifiers = ["Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Visualization"]
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
dev = ["pytest>=7", "build>=1"]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/peterDataScientia/figentra"
|
|
22
|
+
Repository = "https://github.com/peterDataScientia/figentra"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
|
26
|
+
|
|
27
|
+
[tool.pytest.ini_options]
|
|
28
|
+
testpaths = ["tests"]
|
figentra-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"""Figentra: approved scientific figure styling and export."""
|
|
2
|
+
from .style import APPROVED_STYLE, apply_style, new_figure, style_axes, legend_bold, save_figure, style_context
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
__all__ = ["APPROVED_STYLE", "apply_style", "new_figure", "style_axes", "legend_bold", "save_figure", "style_context", "__version__"]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Approved figure settings extracted from SNT100_MASTER_STYLE_1_TO_11.ipynb.
|
|
2
|
+
|
|
3
|
+
Only presentation is changed; scientific observations and fits are untouched.
|
|
4
|
+
"""
|
|
5
|
+
from contextlib import contextmanager
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import matplotlib as mpl
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
|
|
10
|
+
APPROVED_STYLE = {
|
|
11
|
+
"size_mm": (130, 100), "font_family": "DejaVu Sans",
|
|
12
|
+
"base_font_pt": 12, "axis_label_pt": 15, "tick_label_pt": 12,
|
|
13
|
+
"legend_pt": 11, "axes_width_pt": 2.0, "tick_width_pt": 2.0,
|
|
14
|
+
"tick_length_pt": 6, "label_pad": 7, "dpi": 600,
|
|
15
|
+
"formats": ("png", "pdf", "svg"),
|
|
16
|
+
}
|
|
17
|
+
_RC = {
|
|
18
|
+
"font.family": "DejaVu Sans", "font.size": 12,
|
|
19
|
+
"axes.labelsize": 15, "axes.labelweight": "bold",
|
|
20
|
+
"xtick.labelsize": 12, "ytick.labelsize": 12,
|
|
21
|
+
"axes.linewidth": 2.0, "pdf.fonttype": 42,
|
|
22
|
+
"svg.fonttype": "none", "savefig.facecolor": "white",
|
|
23
|
+
"figure.facecolor": "white", "axes.facecolor": "white",
|
|
24
|
+
"axes.grid": False,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def apply_style():
|
|
28
|
+
"""Apply approved Matplotlib defaults globally."""
|
|
29
|
+
mpl.rcParams.update(_RC)
|
|
30
|
+
|
|
31
|
+
@contextmanager
|
|
32
|
+
def style_context():
|
|
33
|
+
"""Apply the approved style temporarily, without global leakage."""
|
|
34
|
+
with mpl.rc_context(rc=_RC):
|
|
35
|
+
yield
|
|
36
|
+
|
|
37
|
+
def new_figure(*, size_mm=None, **kwargs):
|
|
38
|
+
"""Create figure and axes using the approved 130 × 100 mm canvas."""
|
|
39
|
+
apply_style()
|
|
40
|
+
w, h = size_mm or APPROVED_STYLE["size_mm"]
|
|
41
|
+
fig, ax = plt.subplots(figsize=(w / 25.4, h / 25.4), **kwargs)
|
|
42
|
+
style_axes(ax)
|
|
43
|
+
return fig, ax
|
|
44
|
+
|
|
45
|
+
def style_axes(ax, *, xlabel=None, ylabel=None):
|
|
46
|
+
"""Enforce approved spines, ticks, labels, and white background."""
|
|
47
|
+
for side in ("top", "right"):
|
|
48
|
+
ax.spines[side].set_visible(False)
|
|
49
|
+
for side in ("left", "bottom"):
|
|
50
|
+
ax.spines[side].set_visible(True)
|
|
51
|
+
ax.spines[side].set_linewidth(2)
|
|
52
|
+
ax.tick_params(axis="both", which="major", width=2,
|
|
53
|
+
length=6, direction="out", labelsize=12)
|
|
54
|
+
ax.minorticks_off()
|
|
55
|
+
ax.grid(False)
|
|
56
|
+
ax.set_facecolor("white")
|
|
57
|
+
if xlabel is not None:
|
|
58
|
+
ax.set_xlabel(xlabel)
|
|
59
|
+
if ylabel is not None:
|
|
60
|
+
ax.set_ylabel(ylabel)
|
|
61
|
+
for label in (ax.xaxis.label, ax.yaxis.label):
|
|
62
|
+
label.set_fontsize(15)
|
|
63
|
+
label.set_fontweight("bold")
|
|
64
|
+
ax.xaxis.labelpad = 7
|
|
65
|
+
ax.yaxis.labelpad = 7
|
|
66
|
+
for label in ax.get_xticklabels() + ax.get_yticklabels():
|
|
67
|
+
label.set_fontsize(12)
|
|
68
|
+
label.set_fontweight("bold")
|
|
69
|
+
return ax
|
|
70
|
+
|
|
71
|
+
def legend_bold(ax, **kwargs):
|
|
72
|
+
"""Apply the approved 11-point, bold, frameless legend."""
|
|
73
|
+
kwargs.setdefault("frameon", False)
|
|
74
|
+
kwargs.setdefault("prop", {"weight": "bold", "size": 11})
|
|
75
|
+
return ax.legend(**kwargs)
|
|
76
|
+
|
|
77
|
+
def save_figure(fig, name, *, output_dir=".", formats=None, dpi=None, close=False):
|
|
78
|
+
"""Save PNG/PDF/SVG; returns list of Path objects."""
|
|
79
|
+
name = str(name)
|
|
80
|
+
if not name or Path(name).name != name or Path(name).suffix:
|
|
81
|
+
raise ValueError("name must be a filename stem without directories or extension")
|
|
82
|
+
folder = Path(output_dir)
|
|
83
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
84
|
+
formats = tuple(formats or APPROVED_STYLE["formats"])
|
|
85
|
+
if not formats or any(f not in ("png", "pdf", "svg") for f in formats):
|
|
86
|
+
raise ValueError("formats must contain png, pdf or svg")
|
|
87
|
+
saved = []
|
|
88
|
+
for fmt in formats:
|
|
89
|
+
path = folder / (name + "." + fmt)
|
|
90
|
+
fig.savefig(path, dpi=dpi or APPROVED_STYLE["dpi"], facecolor="white")
|
|
91
|
+
saved.append(path)
|
|
92
|
+
if close:
|
|
93
|
+
plt.close(fig)
|
|
94
|
+
return saved
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: figentra
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reproducible publication-ready scientific figure styling for Matplotlib
|
|
5
|
+
Author: peterDataScientia
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/peterDataScientia/figentra
|
|
8
|
+
Project-URL: Repository, https://github.com/peterDataScientia/figentra
|
|
9
|
+
Keywords: matplotlib,scientific-figures,publication,visualization
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: matplotlib>=3.6
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
18
|
+
Requires-Dist: build>=1; extra == "dev"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# Figentra
|
|
22
|
+
|
|
23
|
+
**Scientific figures. Consistently refined.**
|
|
24
|
+
|
|
25
|
+
Figentra is a lightweight Matplotlib styling package that reproduces the approved scientific figure settings from the `SNT100_MASTER_STYLE_1_TO_11.ipynb` research notebook.
|
|
26
|
+
|
|
27
|
+
**Figentra only changes presentation**. It does not modify data, fit models, smooth curves, normalize measurements or fabricate experimental results.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Install from the official GitHub repository today:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install git+https://github.com/peterDataScientia/figentra.git
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For local development:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/peterDataScientia/figentra.git
|
|
41
|
+
cd figentra
|
|
42
|
+
pip install -e ".[dev]"
|
|
43
|
+
pytest -q
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `pip install figentra` command will become available **after** the first successful PyPI release.
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import numpy as np
|
|
52
|
+
from figentra import new_figure, style_axes, legend_bold, save_figure
|
|
53
|
+
|
|
54
|
+
x = np.linspace(0, 120, 200)
|
|
55
|
+
y = np.exp(-x / 40) # illustration, not experimental data
|
|
56
|
+
|
|
57
|
+
fig, ax = new_figure()
|
|
58
|
+
ax.plot(x, y, lw=2, label="Example")
|
|
59
|
+
style_axes(ax, xlabel="Time [s]", ylabel="Response [a.u.]")
|
|
60
|
+
legend_bold(ax)
|
|
61
|
+
fig.subplots_adjust(left=.22, right=.92, bottom=.15, top=.81)
|
|
62
|
+
save_figure(fig, "Figure_01", output_dir="figures", close=True)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To style an existing Matplotlib figure:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from figentra import apply_style, style_axes
|
|
69
|
+
apply_style()
|
|
70
|
+
# draw with Matplotlib
|
|
71
|
+
style_axes(ax)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For temporary style changes without altering global configuration, use `with style_context():`.
|
|
75
|
+
|
|
76
|
+
## Approved visual standards
|
|
77
|
+
|
|
78
|
+
| Setting | Value |
|
|
79
|
+
|---|---|
|
|
80
|
+
| Canvas | 130 × 100 mm |
|
|
81
|
+
| Font | DejaVu Sans |
|
|
82
|
+
| Base font | 12 pt |
|
|
83
|
+
| Axis labels | 15 pt, bold |
|
|
84
|
+
| Tick labels | 12 pt, bold |
|
|
85
|
+
| Legend | 11 pt, bold, no frame |
|
|
86
|
+
| Axes | Left/bottom 2 pt; top/right hidden |
|
|
87
|
+
| Major ticks | 2 pt wide, 6 pt long, outward |
|
|
88
|
+
| Minor ticks and grid | Disabled |
|
|
89
|
+
| Background | White |
|
|
90
|
+
| Export formats | PNG, PDF and SVG |
|
|
91
|
+
| Raster export | 600 dpi |
|
|
92
|
+
| Vector font settings | PDF fonttype 42; SVG fonttype none |
|
|
93
|
+
|
|
94
|
+
Approved figure-specific colors, data scales, legend positioning and `subplots_adjust` are deliberately controlled by each plot rather than forced globally.
|
|
95
|
+
|
|
96
|
+
## Python API
|
|
97
|
+
|
|
98
|
+
- `apply_style()`: enable approved global Matplotlib styling
|
|
99
|
+
- `style_context()`: temporary styling context
|
|
100
|
+
- `new_figure(size_mm=None)`: create a 130 × 100 mm figure and axes
|
|
101
|
+
- `style_axes(ax, xlabel=None, ylabel=None)`: standardize labels, ticks, spines
|
|
102
|
+
- `legend_bold(ax, **kwargs)`: frame-free bold legend
|
|
103
|
+
- `save_figure(fig, stem, output_dir=".", formats=None, dpi=None, close=False)`: export all formats
|
|
104
|
+
|
|
105
|
+
## Release and PyPI
|
|
106
|
+
|
|
107
|
+
GitHub Actions tests Python 3.9, 3.11 and 3.13 on push/PR. A separate release workflow builds and publishes using PyPI Trusted Publishing. To activate public `pip install figentra`, configure a trusted publisher on PyPI using GitHub owner `peterDataScientia`, repository `figentra`, workflow `publish.yml`, environment `pypi`; create the GitHub `pypi` environment and publish a GitHub Release after CI passes. Publishing requires your own PyPI authorization; simply pushing this repository does not publish the package.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/figentra/__init__.py
|
|
5
|
+
src/figentra/style.py
|
|
6
|
+
src/figentra.egg-info/PKG-INFO
|
|
7
|
+
src/figentra.egg-info/SOURCES.txt
|
|
8
|
+
src/figentra.egg-info/dependency_links.txt
|
|
9
|
+
src/figentra.egg-info/requires.txt
|
|
10
|
+
src/figentra.egg-info/top_level.txt
|
|
11
|
+
tests/test_style.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
figentra
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import matplotlib
|
|
2
|
+
matplotlib.use("Agg")
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import pytest
|
|
5
|
+
from figentra import new_figure, style_axes, legend_bold, save_figure, style_context
|
|
6
|
+
|
|
7
|
+
def test_canvas_and_axes():
|
|
8
|
+
fig, ax = new_figure()
|
|
9
|
+
assert tuple(round(x * 25.4, 3) for x in fig.get_size_inches()) == (130, 100)
|
|
10
|
+
style_axes(ax, xlabel="Time [s]", ylabel="Power [µW]")
|
|
11
|
+
assert ax.xaxis.label.get_fontsize() == 15
|
|
12
|
+
assert ax.xaxis.label.get_fontweight() == "bold"
|
|
13
|
+
assert ax.spines["left"].get_linewidth() == 2
|
|
14
|
+
assert not ax.spines["top"].get_visible()
|
|
15
|
+
plt.close(fig)
|
|
16
|
+
|
|
17
|
+
def test_export(tmp_path):
|
|
18
|
+
fig, ax = new_figure()
|
|
19
|
+
ax.plot([1, 2], [2, 3], label="Example")
|
|
20
|
+
legend_bold(ax)
|
|
21
|
+
paths = save_figure(fig, "Figure_01", output_dir=tmp_path, close=True)
|
|
22
|
+
assert {p.suffix for p in paths} == {".png", ".pdf", ".svg"}
|
|
23
|
+
assert all(p.stat().st_size > 100 for p in paths)
|
|
24
|
+
|
|
25
|
+
def test_invalid_filename(tmp_path):
|
|
26
|
+
fig, _ = new_figure()
|
|
27
|
+
with pytest.raises(ValueError):
|
|
28
|
+
save_figure(fig, "../unsafe", output_dir=tmp_path)
|
|
29
|
+
plt.close(fig)
|
|
30
|
+
|
|
31
|
+
def test_style_context_restores_settings():
|
|
32
|
+
previous = matplotlib.rcParams["axes.linewidth"]
|
|
33
|
+
with style_context():
|
|
34
|
+
assert matplotlib.rcParams["axes.linewidth"] == 2
|
|
35
|
+
assert matplotlib.rcParams["axes.linewidth"] == previous
|