labplotlib 0.1.0__py3-none-any.whl → 0.2.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.
labplotlib/__init__.py CHANGED
@@ -1,3 +1,17 @@
1
- from .Symbols import print_symbols, search, symbols
1
+ from .plots import errorbar_plot, line_plot, scatter_with_fit
2
+ from .styling import apply_theme, finish_plot, style_axis
3
+ from .symbols import print_symbols, search, symbols
2
4
 
3
- __all__ = ["symbols", "search", "print_symbols"]
5
+ __version__ = "0.2.0"
6
+
7
+ __all__ = [
8
+ "apply_theme",
9
+ "errorbar_plot",
10
+ "finish_plot",
11
+ "line_plot",
12
+ "print_symbols",
13
+ "scatter_with_fit",
14
+ "search",
15
+ "style_axis",
16
+ "symbols",
17
+ ]
labplotlib/plots.py ADDED
@@ -0,0 +1,81 @@
1
+ from typing import Optional, Sequence
2
+
3
+ import numpy as np
4
+ from matplotlib import pyplot as plt
5
+ from matplotlib.figure import Figure
6
+
7
+ from .styling import PathLike, apply_theme, finish_plot, style_axis
8
+
9
+
10
+ def _new_figure(figsize):
11
+ apply_theme()
12
+ return plt.subplots(figsize=figsize)
13
+
14
+
15
+ def line_plot(
16
+ x: Sequence[float],
17
+ y: Sequence[float],
18
+ title: Optional[str] = None,
19
+ xlabel: Optional[str] = None,
20
+ ylabel: Optional[str] = None,
21
+ filename: Optional[str] = None,
22
+ save_directory: Optional[PathLike] = None,
23
+ show: bool = True,
24
+ figsize=(8, 5),
25
+ ) -> Figure:
26
+ """Plot ``y`` against ``x`` as a line and return the figure."""
27
+ fig, ax = _new_figure(figsize)
28
+ ax.plot(x, y)
29
+ style_axis(ax, title, xlabel, ylabel)
30
+ return finish_plot(fig, filename, save_directory, show)
31
+
32
+
33
+ def scatter_with_fit(
34
+ x: Sequence[float],
35
+ y: Sequence[float],
36
+ degree: int = 1,
37
+ title: Optional[str] = None,
38
+ xlabel: Optional[str] = None,
39
+ ylabel: Optional[str] = None,
40
+ filename: Optional[str] = None,
41
+ save_directory: Optional[PathLike] = None,
42
+ show: bool = True,
43
+ figsize=(8, 5),
44
+ ) -> Figure:
45
+ """Scatter the data with a least-squares polynomial fit of ``degree``."""
46
+ x_values = np.asarray(x, dtype=float)
47
+ y_values = np.asarray(y, dtype=float)
48
+ if x_values.shape != y_values.shape:
49
+ raise ValueError("x and y must have the same shape")
50
+ if degree < 1 or x_values.size <= degree:
51
+ raise ValueError("degree must be >= 1 and less than the number of points")
52
+
53
+ coefficients = np.polyfit(x_values, y_values, degree)
54
+ fit_x = np.linspace(x_values.min(), x_values.max(), 200)
55
+
56
+ fig, ax = _new_figure(figsize)
57
+ ax.scatter(x_values, y_values, label="data")
58
+ ax.plot(fit_x, np.polyval(coefficients, fit_x), color="C1", label=f"fit (degree {degree})")
59
+ ax.legend()
60
+ style_axis(ax, title, xlabel, ylabel)
61
+ return finish_plot(fig, filename, save_directory, show)
62
+
63
+
64
+ def errorbar_plot(
65
+ x: Sequence[float],
66
+ y: Sequence[float],
67
+ yerr: Optional[Sequence[float]] = None,
68
+ xerr: Optional[Sequence[float]] = None,
69
+ title: Optional[str] = None,
70
+ xlabel: Optional[str] = None,
71
+ ylabel: Optional[str] = None,
72
+ filename: Optional[str] = None,
73
+ save_directory: Optional[PathLike] = None,
74
+ show: bool = True,
75
+ figsize=(8, 5),
76
+ ) -> Figure:
77
+ """Plot ``y`` against ``x`` with optional error bars."""
78
+ fig, ax = _new_figure(figsize)
79
+ ax.errorbar(x, y, yerr=yerr, xerr=xerr, fmt="o", capsize=3)
80
+ style_axis(ax, title, xlabel, ylabel)
81
+ return finish_plot(fig, filename, save_directory, show)
labplotlib/py.typed ADDED
File without changes
labplotlib/styling.py ADDED
@@ -0,0 +1,46 @@
1
+ from pathlib import Path
2
+ from typing import Optional, Union
3
+
4
+ import seaborn as sns
5
+ from matplotlib import pyplot as plt
6
+ from matplotlib.axes import Axes
7
+ from matplotlib.figure import Figure
8
+
9
+ PathLike = Union[str, Path]
10
+
11
+
12
+ def apply_theme() -> None:
13
+ """Apply the library's Seaborn theme globally."""
14
+ sns.set_theme(style="darkgrid", rc={"axes.facecolor": ".9"})
15
+
16
+
17
+ def style_axis(
18
+ ax: Axes,
19
+ title: Optional[str] = None,
20
+ xlabel: Optional[str] = None,
21
+ ylabel: Optional[str] = None,
22
+ ) -> None:
23
+ """Set a bold title and axis labels on ``ax``."""
24
+ ax.set(xlabel=xlabel, ylabel=ylabel)
25
+ if title:
26
+ ax.set_title(title, fontdict={"fontsize": 14, "fontweight": "bold"})
27
+
28
+
29
+ def finish_plot(
30
+ fig: Figure,
31
+ filename: Optional[str] = None,
32
+ save_directory: Optional[PathLike] = None,
33
+ show: bool = True,
34
+ ) -> Figure:
35
+ """
36
+ Tidy the layout, optionally save the figure, optionally show it,
37
+ and return it. The save directory is created if it does not exist.
38
+ """
39
+ fig.tight_layout()
40
+ if filename is not None:
41
+ directory = Path(save_directory) if save_directory is not None else Path.cwd()
42
+ directory.mkdir(parents=True, exist_ok=True)
43
+ fig.savefig(directory / filename)
44
+ if show:
45
+ plt.show()
46
+ return fig
@@ -1,4 +1,5 @@
1
1
  from types import MappingProxyType
2
+ from typing import Mapping
2
3
 
3
4
  symbols = MappingProxyType(
4
5
  {
@@ -13,7 +14,7 @@ symbols = MappingProxyType(
13
14
  "set_is_superset_of": "⊇",
14
15
  "set_is_proper_superset_of": "⊃",
15
16
  "set_is_not_superset_of": "⊅",
16
- "set_universal": "ξ",
17
+ "set_universal": "𝕌",
17
18
  "set_minus": "∖",
18
19
  "set_cartesian_product": "×",
19
20
  "set_difference": "\\",
@@ -75,7 +76,7 @@ symbols = MappingProxyType(
75
76
  "degree_celsius": "°C",
76
77
  "degree_fahrenheit": "°F",
77
78
  "diameter": "⌀",
78
- "multiplication": "✕",
79
+ "multiplication": "×",
79
80
  "division": "÷",
80
81
  "left_floor": "⌊",
81
82
  "right_floor": "⌋",
@@ -91,7 +92,7 @@ symbols = MappingProxyType(
91
92
  "top_half_integral": "⌠",
92
93
  "bottom_half_integral": "⌡",
93
94
  "not_sign": "¬",
94
- "+/-": "±",
95
+ "plus_minus": "±",
95
96
  "square_root": "√",
96
97
  "cube_root": "∛",
97
98
  "fourth_root": "∜",
@@ -100,7 +101,8 @@ symbols = MappingProxyType(
100
101
  "right_angle": "∟",
101
102
  "angle": "∠",
102
103
  "therefore": "∴",
103
- "approximately_equal_to": "≅",
104
+ "approximately_equal_to": "≈",
105
+ "congruent_to": "≅",
104
106
  "not_equal_to": "≠",
105
107
  "less_than_or_equal_to": "≤",
106
108
  "greater_than_or_equal_to": "≥",
@@ -112,31 +114,30 @@ symbols = MappingProxyType(
112
114
  )
113
115
 
114
116
 
115
- def search(namelike: str) -> MappingProxyType:
116
-
117
+ def search(namelike: str) -> Mapping[str, str]:
118
+ """
119
+ Return a read-only mapping of the symbols whose names contain
120
+ ``namelike``. The match is case-insensitive.
117
121
  """
118
- Return a dictionary of symbols with names
119
- containing namelike argument
120
- """
121
122
 
122
- filtered = {k: v for k, v in symbols.items() if namelike in k}
123
+ needle = namelike.lower()
124
+ filtered = {k: v for k, v in symbols.items() if needle in k.lower()}
123
125
 
124
126
  return MappingProxyType(filtered)
125
127
 
126
128
 
127
- def print_symbols(symbols_to_print:MappingProxyType = symbols) -> None:
129
+ def _hex_escape(char: str) -> str:
130
+ code = ord(char)
131
+ return f"\\u{code:04x}" if code <= 0xFFFF else f"\\U{code:08x}"
128
132
 
133
+
134
+ def print_symbols(symbols_to_print: Mapping[str, str] = symbols) -> None:
129
135
  """
130
- Prints symbols in the symbols argument,
131
- or all if this is omitted
136
+ Print the symbols in ``symbols_to_print`` (all symbols by default)
137
+ with their decimal and hexadecimal code points.
132
138
  """
133
139
 
134
- for symbol in symbols_to_print.keys():
135
-
136
- print(f"{symbol.ljust(32, ' ')}", end="")
137
-
138
- print(f" {symbols_to_print[symbol]}", end="")
139
-
140
- print(f" decimal: {str(ord(symbols_to_print[symbol])).ljust(5, ' ')}", end="")
141
-
142
- print(f" hexadecimal: \\u{hex(ord(symbols_to_print[symbol]))[2:]}")
140
+ for name, value in symbols_to_print.items():
141
+ decimal = " ".join(str(ord(c)) for c in value)
142
+ hexadecimal = " ".join(_hex_escape(c) for c in value)
143
+ print(f"{name:<32} {value} decimal: {decimal:<8} hexadecimal: {hexadecimal}")
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: labplotlib
3
+ Version: 0.2.0
4
+ Summary: Plot styling helpers and searchable mathematical symbols.
5
+ Author: iancullinane06
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/iancullinane06/LabPlotLib
8
+ Project-URL: Issues, https://github.com/iancullinane06/LabPlotLib/issues
9
+ Project-URL: Changelog, https://github.com/iancullinane06/LabPlotLib/blob/main/CHANGELOG.md
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: matplotlib>=3.5
18
+ Requires-Dist: numpy>=1.21
19
+ Requires-Dist: seaborn>=0.11.2
20
+ Provides-Extra: dev
21
+ Requires-Dist: ruff; extra == "dev"
22
+ Requires-Dist: build; extra == "dev"
23
+ Requires-Dist: twine; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # LabPlotLib
27
+
28
+ LabPlotLib is a small Python library containing plotting-style helpers and a
29
+ searchable collection of mathematical symbols.
30
+
31
+ ## Installation
32
+
33
+ Install the latest source checkout with pip:
34
+
35
+ ```powershell
36
+ python -m pip install .
37
+ ```
38
+
39
+ For development, install it in editable mode:
40
+
41
+ ```powershell
42
+ python -m pip install -e .
43
+ ```
44
+
45
+ ## Symbol utilities
46
+
47
+ ```python
48
+ from labplotlib import print_symbols, search, symbols
49
+
50
+ print(symbols["set_union"])
51
+ print(search("fraction"))
52
+ print_symbols(search("fraction_one"))
53
+ ```
54
+
55
+ The `symbols` mapping is read-only. `search(name_part)` returns a read-only
56
+ mapping of symbol names containing `name_part` (case-insensitive).
57
+
58
+ ## Plotting
59
+
60
+ ```python
61
+ from labplotlib import errorbar_plot, line_plot, scatter_with_fit
62
+
63
+ line_plot([1, 2, 3], [1, 4, 9], title="Squares", xlabel="x", ylabel="y")
64
+ scatter_with_fit(x, y, degree=1, filename="fit.png", save_directory="plots")
65
+ errorbar_plot(x, y, yerr=err, show=False) # returns the matplotlib Figure
66
+ ```
67
+
68
+ Each function returns the `Figure`. Pass `filename` (and optionally
69
+ `save_directory`, created if missing) to save, and `show=False` to skip
70
+ `plt.show()`. Importing the package does not change global matplotlib
71
+ settings; the plot functions apply the Seaborn theme via `apply_theme()`, which
72
+ you can also call yourself. Lower-level helpers `style_axis` and `finish_plot`
73
+ are public too.
74
+
75
+ ## Development
76
+
77
+ ```powershell
78
+ python -m pip install -e ".[dev]"
79
+ ruff check .
80
+ python -m unittest discover -s tests
81
+ ```
82
+
83
+ The version lives in `src/labplotlib/__init__.py`; see
84
+ [CHANGELOG.md](CHANGELOG.md) for release notes.
85
+
86
+ ## Publishing
87
+
88
+ Publishing is automated when a GitHub Release is published. Configure a PyPI
89
+ trusted publisher for this repository with:
90
+
91
+ - Owner and repository: the values for this GitHub project
92
+ - Workflow: `.github/workflows/publish.yml`
93
+ - Environment: `pypi`
94
+
95
+ Then update the version in `pyproject.toml`, push the change, and create a
96
+ GitHub Release with a matching version tag (for example, `v0.1.1`). The
97
+ workflow runs the tests, builds the distributions, and publishes them without
98
+ requiring a PyPI API token in GitHub secrets.
@@ -0,0 +1,10 @@
1
+ labplotlib/__init__.py,sha256=xk7cm4ukpfIh6wpC4NhlkxFamkKMcJnnEzzyL_8b3gk,395
2
+ labplotlib/plots.py,sha256=IoRHCPwZEIC7rz70kxz8eUF-jg2R9MFcHRcbO94jZWE,2701
3
+ labplotlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ labplotlib/styling.py,sha256=6VOduEAhnynZ7W3zu4JZvyzD_4rYFOih84na0Rbx5xs,1333
5
+ labplotlib/symbols.py,sha256=0s8CuEoK6V7vL3CZztfzA4V8YxYTMYhBlwpaRvq24VM,4916
6
+ labplotlib-0.2.0.dist-info/licenses/LICENSE,sha256=qtD8JTBOufwHP-9RzB6ONro1LXlcdx-w6Xwk8-1zk28,1092
7
+ labplotlib-0.2.0.dist-info/METADATA,sha256=815QUev1vwGyctyyw1FulrZHbP5RaIamjREs0J4iwH4,3117
8
+ labplotlib-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
9
+ labplotlib-0.2.0.dist-info/top_level.txt,sha256=n1nselG8yl820GQWj11wPJIjWlToFxTfK2nIOc1x7VU,11
10
+ labplotlib-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iancullinane06
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.
labplotlib/Styling.py DELETED
@@ -1,20 +0,0 @@
1
- import seaborn as sns
2
- from matplotlib import pyplot as plt
3
-
4
- sns.set_theme(style="darkgrid", rc={"axes.facecolor": ".9"})
5
-
6
- def _style_axis(ax, title, xlabel, ylabel):
7
- ax.set(
8
- xlabel=xlabel,
9
- ylabel=ylabel
10
- )
11
- ax.set_title(title, fontdict={"fontsize": 14, "fontweight": "bold"})
12
-
13
-
14
- def _finish_plot(fig, filename, save_directory):
15
- fig.tight_layout()
16
- fig.savefig(f"{save_directory}/{filename}")
17
- plt.show()
18
-
19
- if __name__ == "__main__":
20
- pass
@@ -1,58 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: labplotlib
3
- Version: 0.1.0
4
- Summary: Plot styling helpers and searchable mathematical symbols.
5
- Classifier: Programming Language :: Python :: 3
6
- Classifier: Operating System :: OS Independent
7
- Requires-Python: >=3.9
8
- Description-Content-Type: text/markdown
9
- Requires-Dist: matplotlib>=3.5
10
- Requires-Dist: seaborn>=0.11.2
11
-
12
- # LabPlotLib
13
-
14
- LabPlotLib is a small Python library containing plotting-style helpers and a
15
- searchable collection of mathematical symbols.
16
-
17
- ## Installation
18
-
19
- Install the latest source checkout with pip:
20
-
21
- ```powershell
22
- python -m pip install .
23
- ```
24
-
25
- For development, install it in editable mode:
26
-
27
- ```powershell
28
- python -m pip install -e .
29
- ```
30
-
31
- ## Symbol utilities
32
-
33
- ```python
34
- from labplotlib import print_symbols, search, symbols
35
-
36
- print(symbols["set_union"])
37
- print(search("fraction"))
38
- print_symbols(search("fraction_one"))
39
- ```
40
-
41
- The `symbols` mapping is read-only. `search(name_part)` returns a read-only
42
- mapping containing symbol names that include `name_part`.
43
-
44
- Importing `labplotlib.Styling` applies the library's Seaborn plotting theme.
45
-
46
- ## Publishing
47
-
48
- Publishing is automated when a GitHub Release is published. Configure a PyPI
49
- trusted publisher for this repository with:
50
-
51
- - Owner and repository: the values for this GitHub project
52
- - Workflow: `.github/workflows/publish.yml`
53
- - Environment: `pypi`
54
-
55
- Then update the version in `pyproject.toml`, push the change, and create a
56
- GitHub Release with a matching version tag (for example, `v0.1.1`). The
57
- workflow runs the tests, builds the distributions, and publishes them without
58
- requiring a PyPI API token in GitHub secrets.
@@ -1,7 +0,0 @@
1
- labplotlib/Styling.py,sha256=EV1R6gRcERnbtpuyA9XVucI-4sYmaJl4pd2c-mVJ6i0,502
2
- labplotlib/Symbols.py,sha256=iQVXY3NPSqq0tVEp7o1mHROvIkBrNeXcT4ECC9l6SoY,4667
3
- labplotlib/__init__.py,sha256=nkMH8auQivc9vbjZaFyAsZ5rM_Jqisl4PxTsxAZeYe0,105
4
- labplotlib-0.1.0.dist-info/METADATA,sha256=QfPmJPPBPFx-SE0qwlGCr_XW_5a2MWwh-AX6ud2yKAE,1668
5
- labplotlib-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
- labplotlib-0.1.0.dist-info/top_level.txt,sha256=n1nselG8yl820GQWj11wPJIjWlToFxTfK2nIOc1x7VU,11
7
- labplotlib-0.1.0.dist-info/RECORD,,