aiken-engineering 0.1.0__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.
- aiken_engineering-0.1.0.dist-info/METADATA +24 -0
- aiken_engineering-0.1.0.dist-info/RECORD +35 -0
- aiken_engineering-0.1.0.dist-info/WHEEL +5 -0
- aiken_engineering-0.1.0.dist-info/licenses/LICENSE +21 -0
- aiken_engineering-0.1.0.dist-info/top_level.txt +1 -0
- engineering_tools/__init__.py +31 -0
- engineering_tools/ansys_tools/__init__.py +0 -0
- engineering_tools/ansys_tools/ansys_file_ops.py +0 -0
- engineering_tools/ansys_tools/read_elements.py +0 -0
- engineering_tools/ansys_tools/read_nodes.py +0 -0
- engineering_tools/ansys_tools/read_pretab.py +0 -0
- engineering_tools/ansys_tools/read_prnsol.py +0 -0
- engineering_tools/bolts/__init__.py +0 -0
- engineering_tools/core/__init__.py +0 -0
- engineering_tools/fatigue/__init__.py +0 -0
- engineering_tools/fatigue/asme_fatigue_curves.py +0 -0
- engineering_tools/fatigue/dnv_fatigue_curves.py +0 -0
- engineering_tools/impact/__init__.py +0 -0
- engineering_tools/impact/concrete_impact.py +0 -0
- engineering_tools/impact/fea_impact.py +0 -0
- engineering_tools/impact/impact_helpers.py +0 -0
- engineering_tools/impact/metals_impact.py +0 -0
- engineering_tools/impact/poly_carbonate_impact.py +0 -0
- engineering_tools/materials/__init__.py +0 -0
- engineering_tools/materials/true_stress_true_strain.py +1 -0
- engineering_tools/plotting/__init__.py +63 -0
- engineering_tools/plotting/colors.py +126 -0
- engineering_tools/plotting/fatigue_plots.py +0 -0
- engineering_tools/plotting/impact_plots.py +0 -0
- engineering_tools/plotting/plotting_helpers.py +0 -0
- engineering_tools/plotting/stress_strain_plots.py +0 -0
- engineering_tools/plotting/styles.py +181 -0
- engineering_tools/tanks/__init__.py +0 -0
- engineering_tools/units/__init__.py +0 -0
- engineering_tools/utilities/__init__.py +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aiken-engineering
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Engineering utilities.
|
|
5
|
+
Author: Eric Rudolph
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: engineering,plotting,matplotlib,fatigue,impact
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering
|
|
14
|
+
Requires-Python: >=3.14
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: matplotlib>=3.11.0
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest>=9.1.0; extra == "test"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
Copyright (c) 2026 Aiken Engineering
|
|
23
|
+
|
|
24
|
+
MIT License
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
aiken_engineering-0.1.0.dist-info/licenses/LICENSE,sha256=e3aBwfyFwaSl_-9mcOdffgvD1bvGAVtWg8dUwQvNFIc,1074
|
|
2
|
+
engineering_tools/__init__.py,sha256=srcpmef_gY90z77kYxYxmAkkvArxq3XpIgxr0hgnfYI,642
|
|
3
|
+
engineering_tools/ansys_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
engineering_tools/ansys_tools/ansys_file_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
engineering_tools/ansys_tools/read_elements.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
engineering_tools/ansys_tools/read_nodes.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
engineering_tools/ansys_tools/read_pretab.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
engineering_tools/ansys_tools/read_prnsol.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
engineering_tools/bolts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
engineering_tools/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
engineering_tools/fatigue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
engineering_tools/fatigue/asme_fatigue_curves.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
engineering_tools/fatigue/dnv_fatigue_curves.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
engineering_tools/impact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
engineering_tools/impact/concrete_impact.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
engineering_tools/impact/fea_impact.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
engineering_tools/impact/impact_helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
engineering_tools/impact/metals_impact.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
engineering_tools/impact/poly_carbonate_impact.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
engineering_tools/materials/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
engineering_tools/materials/true_stress_true_strain.py,sha256=OZYVLSHiSqs6cuRbdoZ7liRtDIpo4OmGWPkV74_jOZc,30
|
|
22
|
+
engineering_tools/plotting/__init__.py,sha256=E9waV0FS45M33ZIiErVcy2ngLbpojCEAZIOyiCHdNAI,1369
|
|
23
|
+
engineering_tools/plotting/colors.py,sha256=FMAKC8LPnS0wsv4hubvOvFWLcj2QFmTFaxeM4MWtjtc,3656
|
|
24
|
+
engineering_tools/plotting/fatigue_plots.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
+
engineering_tools/plotting/impact_plots.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
+
engineering_tools/plotting/plotting_helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
|
+
engineering_tools/plotting/stress_strain_plots.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
+
engineering_tools/plotting/styles.py,sha256=LYdHnO_Mpu-3Ut21Uz6Kl-AiSIsEt5v8hWL-BeR1opY,4158
|
|
29
|
+
engineering_tools/tanks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
|
+
engineering_tools/units/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
|
+
engineering_tools/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
+
aiken_engineering-0.1.0.dist-info/METADATA,sha256=_fAJ5w58_ovCGVVkHWpVh54dHzA3IaDIROwHjSVCnpk,763
|
|
33
|
+
aiken_engineering-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
34
|
+
aiken_engineering-0.1.0.dist-info/top_level.txt,sha256=PYhQm6KOvdKCZoKW3569-wzmmglR1XOoowqhNra28zs,18
|
|
35
|
+
aiken_engineering-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aiken Engineering
|
|
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 @@
|
|
|
1
|
+
engineering_tools
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Top-level public API for engineering_tools.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# TODO: Figure out what I really want in the top level API...
|
|
6
|
+
|
|
7
|
+
from engineering_tools.plotting import (
|
|
8
|
+
ENGINEERING_STYLE,
|
|
9
|
+
PRESENTATION_STYLE,
|
|
10
|
+
REPORT_STYLE,
|
|
11
|
+
engineering_style,
|
|
12
|
+
presentation_style,
|
|
13
|
+
report_style,
|
|
14
|
+
reset_style,
|
|
15
|
+
use_engineering_style,
|
|
16
|
+
use_presentation_style,
|
|
17
|
+
use_report_style,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ENGINEERING_STYLE",
|
|
22
|
+
"PRESENTATION_STYLE",
|
|
23
|
+
"REPORT_STYLE",
|
|
24
|
+
"engineering_style",
|
|
25
|
+
"presentation_style",
|
|
26
|
+
"report_style",
|
|
27
|
+
"reset_style",
|
|
28
|
+
"use_engineering_style",
|
|
29
|
+
"use_presentation_style",
|
|
30
|
+
"use_report_style",
|
|
31
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# TODO true stress true strain
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) 2026 Aiken Engineering
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Plotting utilities for engineering_tools.
|
|
6
|
+
|
|
7
|
+
This subpackage provides:
|
|
8
|
+
- Matplotlib style configuration
|
|
9
|
+
- Engineering-focused plotting helpers
|
|
10
|
+
- Domain-specific plotting functions
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from engineering_tools.plotting.styles import (
|
|
14
|
+
ENGINEERING_STYLE,
|
|
15
|
+
PRESENTATION_STYLE,
|
|
16
|
+
REPORT_STYLE,
|
|
17
|
+
engineering_style,
|
|
18
|
+
presentation_style,
|
|
19
|
+
report_style,
|
|
20
|
+
reset_style,
|
|
21
|
+
use_engineering_style,
|
|
22
|
+
use_presentation_style,
|
|
23
|
+
use_report_style,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from engineering_tools.plotting.colors import (
|
|
27
|
+
RGB255,
|
|
28
|
+
RGB01,
|
|
29
|
+
ANSYS_COLORS,
|
|
30
|
+
ANSYS_LISTED_CMAP,
|
|
31
|
+
ANSYS_LINEAR_CMAP,
|
|
32
|
+
validate_rgb255,
|
|
33
|
+
rgb255_to_rgb01,
|
|
34
|
+
rgb255_sequence_to_rgb01,
|
|
35
|
+
make_listed_colormap,
|
|
36
|
+
make_linear_colormap,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
# Styles
|
|
41
|
+
"ENGINEERING_STYLE",
|
|
42
|
+
"PRESENTATION_STYLE",
|
|
43
|
+
"REPORT_STYLE",
|
|
44
|
+
"engineering_style",
|
|
45
|
+
"presentation_style",
|
|
46
|
+
"report_style",
|
|
47
|
+
"reset_style",
|
|
48
|
+
"use_engineering_style",
|
|
49
|
+
"use_presentation_style",
|
|
50
|
+
"use_report_style",
|
|
51
|
+
|
|
52
|
+
# Colors
|
|
53
|
+
"RGB255",
|
|
54
|
+
"RGB01",
|
|
55
|
+
"ANSYS_COLORS",
|
|
56
|
+
"ANSYS_LISTED_CMAP",
|
|
57
|
+
"ANSYS_LINEAR_CMAP",
|
|
58
|
+
"validate_rgb255",
|
|
59
|
+
"rgb255_to_rgb01",
|
|
60
|
+
"rgb255_sequence_to_rgb01",
|
|
61
|
+
"make_listed_colormap",
|
|
62
|
+
"make_linear_colormap",
|
|
63
|
+
]
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom color palettes and colormaps for engineering plots.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Color sequences are stored as 8-bit RGB tuples by default:
|
|
6
|
+
|
|
7
|
+
(R, G, B)
|
|
8
|
+
|
|
9
|
+
where each channel is in the range 0 to 255.
|
|
10
|
+
|
|
11
|
+
Helper functions are provided to convert these colors into Matplotlib-friendly
|
|
12
|
+
formats.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from typing import TypeAlias
|
|
19
|
+
|
|
20
|
+
from matplotlib.colors import LinearSegmentedColormap, ListedColormap
|
|
21
|
+
|
|
22
|
+
RGB255: TypeAlias = tuple[int, int, int]
|
|
23
|
+
RGB01: TypeAlias = tuple[float, float, float]
|
|
24
|
+
|
|
25
|
+
ANSYS_COLORS: list[RGB255] = [
|
|
26
|
+
(0, 0, 255),
|
|
27
|
+
(0, 160, 255),
|
|
28
|
+
(0, 255, 255),
|
|
29
|
+
(0, 255, 255),
|
|
30
|
+
(0, 255, 0),
|
|
31
|
+
(178, 255, 0),
|
|
32
|
+
(255, 255, 0),
|
|
33
|
+
(255, 145, 0),
|
|
34
|
+
(255, 0, 0),
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def validate_rgb255(colors: Sequence[RGB255]) -> None:
|
|
39
|
+
"""
|
|
40
|
+
Validate a sequence of 8-bit RGB colors.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
colors : Sequence[RGB255]
|
|
45
|
+
Sequence of 8-bit RGB colors - tuples should containe three integers
|
|
46
|
+
in the range 0 to 255.
|
|
47
|
+
|
|
48
|
+
Raises
|
|
49
|
+
------
|
|
50
|
+
ValueError
|
|
51
|
+
If any color in the sequence is not a valid 8-bit RGB color.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
for color in colors:
|
|
55
|
+
if len(color) != 3:
|
|
56
|
+
raise ValueError(f"Expected RGB tuple with 3 channels, got {color!r}.")
|
|
57
|
+
|
|
58
|
+
for channel in color:
|
|
59
|
+
if not isinstance(channel, int):
|
|
60
|
+
raise ValueError(f"Expected integer channel in range 0 to 255, got {channel!r}.")
|
|
61
|
+
|
|
62
|
+
if not 0 <= channel <= 255:
|
|
63
|
+
raise ValueError(f"Expected integer channel in range 0 to 255, got {channel!r}.")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def rgb255_to_rgb01(color: RGB255) -> RGB01:
|
|
67
|
+
"""
|
|
68
|
+
Convert a single RGB color from 0-255 range to 0-1 range.
|
|
69
|
+
|
|
70
|
+
Matplotlib generally expects RGB colors in the range 0 to 1.
|
|
71
|
+
|
|
72
|
+
Examples
|
|
73
|
+
--------
|
|
74
|
+
>>> rgb255_to_rgb01((255, 128, 0))
|
|
75
|
+
(1.0, 0.5019607843137255, 0.0)
|
|
76
|
+
"""
|
|
77
|
+
validate_rgb255([color])
|
|
78
|
+
return tuple(channel / 255 for channel in color)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def rgb255_sequence_to_rgb01(colors: Sequence[RGB255]) -> list[RGB01]:
|
|
82
|
+
"""
|
|
83
|
+
Convert a sequence of 8-bit RGB colors to Matplotlib 0-1 colors.
|
|
84
|
+
"""
|
|
85
|
+
validate_rgb255(colors)
|
|
86
|
+
return [rgb255_to_rgb01(color) for color in colors]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def make_listed_colormap(colors: Sequence[RGB255],
|
|
90
|
+
*,
|
|
91
|
+
name: str = "custom_colormap"
|
|
92
|
+
) -> ListedColormap:
|
|
93
|
+
"""
|
|
94
|
+
Create a Matplotlib ListedColormap from 8-bit RGB colors.
|
|
95
|
+
|
|
96
|
+
A ListedColromap is useful when you want discrete color bands.
|
|
97
|
+
|
|
98
|
+
Examples
|
|
99
|
+
________
|
|
100
|
+
>>> cmap = make_listed_colormap(ANSYS_COLORS, name="ansys")
|
|
101
|
+
"""
|
|
102
|
+
rgb01_colors = rgb255_sequence_to_rgb01(colors)
|
|
103
|
+
return ListedColormap(rgb01_colors, name=name)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def make_linear_colormap(colors: Sequence[RGB255],
|
|
107
|
+
*,
|
|
108
|
+
name: str = "custom_linear_colormap",
|
|
109
|
+
n_colors: int = 256,
|
|
110
|
+
) -> LinearSegmentedColormap:
|
|
111
|
+
"""
|
|
112
|
+
Create a smooth Matplotlib LinearSegmentedColormap from 8-bit RGB colors.
|
|
113
|
+
|
|
114
|
+
A LinearSegmentedColormap is useful when you want smooth interpolation
|
|
115
|
+
between colors.
|
|
116
|
+
|
|
117
|
+
Examples
|
|
118
|
+
--------
|
|
119
|
+
>>> cmap = make_linear_colormap(ANSYS_COLORS, name="ansys_smooth")
|
|
120
|
+
"""
|
|
121
|
+
rgb01_colors = rgb255_sequence_to_rgb01(colors)
|
|
122
|
+
return LinearSegmentedColormap.from_list(name, rgb01_colors, N=n_colors)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
ANSYS_LISTED_CMAP = make_listed_colormap(ANSYS_COLORS, name="ansys")
|
|
126
|
+
ANSYS_LINEAR_CMAP = make_linear_colormap(ANSYS_COLORS, name="ansys_smooth")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"""
|
|
2
|
+
matplotlib style utilities for engineering plots.
|
|
3
|
+
|
|
4
|
+
This module defines rcParams dictionaries and helper functions for
|
|
5
|
+
applying styles temporarily or globally.
|
|
6
|
+
|
|
7
|
+
The main function is:
|
|
8
|
+
|
|
9
|
+
use_engineering_style()
|
|
10
|
+
|
|
11
|
+
For temporary styling, use:
|
|
12
|
+
|
|
13
|
+
with engineering_style():
|
|
14
|
+
...
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from contextlib import contextmanager
|
|
21
|
+
from typing import Iterator
|
|
22
|
+
|
|
23
|
+
import matplotlib as mpl
|
|
24
|
+
import matplotlib.pyplot as plt
|
|
25
|
+
from matplotlib.pyplot import savefig
|
|
26
|
+
|
|
27
|
+
ENGINEERING_STYLE: dict[str, object] = {
|
|
28
|
+
# Figure
|
|
29
|
+
"figure.figsize": (8, 5),
|
|
30
|
+
"figure.dpi": 120,
|
|
31
|
+
"savefig.dpi": 300,
|
|
32
|
+
"savefig.bbox": "tight",
|
|
33
|
+
|
|
34
|
+
# Axes
|
|
35
|
+
"axes.titlesize": 12,
|
|
36
|
+
"axes.labelsize": 10,
|
|
37
|
+
"axes.grid": True,
|
|
38
|
+
"axes.formatter.use_mathtext": True,
|
|
39
|
+
|
|
40
|
+
# ticks
|
|
41
|
+
"xtick.top": True,
|
|
42
|
+
"xtick.labelsize": 8,
|
|
43
|
+
"xtick.direction": "in",
|
|
44
|
+
"xtick.minor.visible": True,
|
|
45
|
+
"ytick.right": True,
|
|
46
|
+
"ytick.labelsize": 8,
|
|
47
|
+
"ytick.direction": "in",
|
|
48
|
+
"ytick.minor.visible": True,
|
|
49
|
+
|
|
50
|
+
# Grid
|
|
51
|
+
"grid.linewidth": 0.5,
|
|
52
|
+
"grid.alpha": 0.35,
|
|
53
|
+
|
|
54
|
+
# legend
|
|
55
|
+
"legend.frameon": True,
|
|
56
|
+
"legend.fontsize": "small",
|
|
57
|
+
"legend.framealpha": 1.0,
|
|
58
|
+
|
|
59
|
+
# Lines
|
|
60
|
+
"lines.linewidth": 2.0,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
REPORT_STYLE: dict[str, object] = {
|
|
64
|
+
**ENGINEERING_STYLE,
|
|
65
|
+
|
|
66
|
+
# Better for reports and saved figures
|
|
67
|
+
"figure.figsize": (6.5, 4.5),
|
|
68
|
+
"figure.dpi": 120,
|
|
69
|
+
"savefig.dpi": 300,
|
|
70
|
+
|
|
71
|
+
# Change text style
|
|
72
|
+
# TODO: Finish developing the REPORT_STYLE
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
PRESENTATION_STYLE: dict[str, object] = {
|
|
76
|
+
**ENGINEERING_STYLE,
|
|
77
|
+
|
|
78
|
+
# Better for slides and large displays
|
|
79
|
+
# TODO: Finish developing the PRESENTATION_STYLE
|
|
80
|
+
|
|
81
|
+
# Larger Text
|
|
82
|
+
|
|
83
|
+
# Heavier Lines
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def use_engineering_style() -> None:
|
|
89
|
+
"""
|
|
90
|
+
Apply the default engineering style globally.
|
|
91
|
+
|
|
92
|
+
This modifies Matplotlib's rcParams for the current Python session.
|
|
93
|
+
|
|
94
|
+
Examples
|
|
95
|
+
--------
|
|
96
|
+
>>> from engineering_tools import use_engineering_style
|
|
97
|
+
>>> use_engineering_style()
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
mpl.rcParams.update(ENGINEERING_STYLE)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def use_report_style() -> None:
|
|
104
|
+
"""
|
|
105
|
+
Apply the report style globally. This style is useful for figures
|
|
106
|
+
intended for documents and reports.
|
|
107
|
+
|
|
108
|
+
This modifies Matplotlib's rcParams for the current Python session.
|
|
109
|
+
|
|
110
|
+
Examples
|
|
111
|
+
--------
|
|
112
|
+
>>> from engineering_tools import use_report_style
|
|
113
|
+
>>> use_report_style()
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
mpl.rcParams.update(REPORT_STYLE)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def use_presentation_style() -> None:
|
|
120
|
+
"""
|
|
121
|
+
Apply the presentation style globally. This style us useful for figures
|
|
122
|
+
intended for slides and screen sharing.
|
|
123
|
+
|
|
124
|
+
This modifies Matplotlib's rcParams for the current Python session.
|
|
125
|
+
|
|
126
|
+
Examples
|
|
127
|
+
--------
|
|
128
|
+
>>> from engineering_tools import use_presentation_style
|
|
129
|
+
>>> use_presentation_style()
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
mpl.rcParams.update(PRESENTATION_STYLE)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def reset_style() -> None:
|
|
136
|
+
"""
|
|
137
|
+
Reset the Matplotlib style settings to Matplotlib defaults.
|
|
138
|
+
"""
|
|
139
|
+
plt.rcdefaults()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@contextmanager
|
|
143
|
+
def engineering_style() -> Iterator[None]:
|
|
144
|
+
"""
|
|
145
|
+
Temporarily apply the default engineering style.
|
|
146
|
+
|
|
147
|
+
This does not permanently modify Matplotlib's global style outside
|
|
148
|
+
the context manager.
|
|
149
|
+
|
|
150
|
+
Examples
|
|
151
|
+
--------
|
|
152
|
+
>>> import matplotlib.pyplot as plt
|
|
153
|
+
>>> from engineering_tools import engineering_style
|
|
154
|
+
>>>
|
|
155
|
+
>>> with engineering_style():
|
|
156
|
+
... fig, ax = plt.subplots()
|
|
157
|
+
... ax.plot([0, 1, 2], [0, 1, 4])
|
|
158
|
+
... ax.set_xlabel("Time [s]")
|
|
159
|
+
... ax.set_ylabel("Displacement [mm]")
|
|
160
|
+
... plt.show()
|
|
161
|
+
"""
|
|
162
|
+
with mpl.rc_context(rc=ENGINEERING_STYLE):
|
|
163
|
+
yield
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@contextmanager
|
|
167
|
+
def report_style() -> Iterator[None]:
|
|
168
|
+
"""
|
|
169
|
+
Temporarily apply the report plotting style.
|
|
170
|
+
"""
|
|
171
|
+
with mpl.rc_context(rc=REPORT_STYLE):
|
|
172
|
+
yield
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@contextmanager
|
|
176
|
+
def presentation_style() -> Iterator[None]:
|
|
177
|
+
"""
|
|
178
|
+
Temporarily apply the presentation plotting style.
|
|
179
|
+
"""
|
|
180
|
+
with mpl.rc_context(rc=PRESENTATION_STYLE):
|
|
181
|
+
yield
|
|
File without changes
|
|
File without changes
|
|
File without changes
|