labplotlib 0.1.0__tar.gz → 0.2.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.
@@ -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.
@@ -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.
@@ -1,14 +1,3 @@
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
1
  # LabPlotLib
13
2
 
14
3
  LabPlotLib is a small Python library containing plotting-style helpers and a
@@ -39,9 +28,35 @@ print_symbols(search("fraction_one"))
39
28
  ```
40
29
 
41
30
  The `symbols` mapping is read-only. `search(name_part)` returns a read-only
42
- mapping containing symbol names that include `name_part`.
31
+ mapping of symbol names containing `name_part` (case-insensitive).
32
+
33
+ ## Plotting
34
+
35
+ ```python
36
+ from labplotlib import errorbar_plot, line_plot, scatter_with_fit
37
+
38
+ line_plot([1, 2, 3], [1, 4, 9], title="Squares", xlabel="x", ylabel="y")
39
+ scatter_with_fit(x, y, degree=1, filename="fit.png", save_directory="plots")
40
+ errorbar_plot(x, y, yerr=err, show=False) # returns the matplotlib Figure
41
+ ```
42
+
43
+ Each function returns the `Figure`. Pass `filename` (and optionally
44
+ `save_directory`, created if missing) to save, and `show=False` to skip
45
+ `plt.show()`. Importing the package does not change global matplotlib
46
+ settings; the plot functions apply the Seaborn theme via `apply_theme()`, which
47
+ you can also call yourself. Lower-level helpers `style_axis` and `finish_plot`
48
+ are public too.
49
+
50
+ ## Development
51
+
52
+ ```powershell
53
+ python -m pip install -e ".[dev]"
54
+ ruff check .
55
+ python -m unittest discover -s tests
56
+ ```
43
57
 
44
- Importing `labplotlib.Styling` applies the library's Seaborn plotting theme.
58
+ The version lives in `src/labplotlib/__init__.py`; see
59
+ [CHANGELOG.md](CHANGELOG.md) for release notes.
45
60
 
46
61
  ## Publishing
47
62
 
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "labplotlib"
7
+ dynamic = ["version"]
8
+ description = "Plot styling helpers and searchable mathematical symbols."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "iancullinane06" }]
13
+ dependencies = [
14
+ "matplotlib>=3.5",
15
+ "numpy>=1.21",
16
+ "seaborn>=0.11.2",
17
+ ]
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ "Typing :: Typed",
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ dev = ["ruff", "build", "twine"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/iancullinane06/LabPlotLib"
30
+ Issues = "https://github.com/iancullinane06/LabPlotLib/issues"
31
+ Changelog = "https://github.com/iancullinane06/LabPlotLib/blob/main/CHANGELOG.md"
32
+
33
+ [tool.setuptools]
34
+ package-dir = { "" = "src" }
35
+
36
+ [tool.setuptools.dynamic]
37
+ version = { attr = "labplotlib.__version__" }
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.setuptools.package-data]
43
+ labplotlib = ["py.typed"]
44
+
45
+ [tool.ruff]
46
+ line-length = 100
47
+ extend-exclude = [".venv"]
48
+
49
+ [tool.ruff.lint]
50
+ select = ["E", "F", "I"]
@@ -0,0 +1,17 @@
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
4
+
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
+ ]
@@ -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)
File without changes
@@ -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.
@@ -1,11 +1,15 @@
1
+ LICENSE
1
2
  README.md
2
3
  pyproject.toml
3
- src/labplotlib/Styling.py
4
- src/labplotlib/Symbols.py
5
4
  src/labplotlib/__init__.py
5
+ src/labplotlib/plots.py
6
+ src/labplotlib/py.typed
7
+ src/labplotlib/styling.py
8
+ src/labplotlib/symbols.py
6
9
  src/labplotlib.egg-info/PKG-INFO
7
10
  src/labplotlib.egg-info/SOURCES.txt
8
11
  src/labplotlib.egg-info/dependency_links.txt
9
12
  src/labplotlib.egg-info/requires.txt
10
13
  src/labplotlib.egg-info/top_level.txt
14
+ tests/test_plots.py
11
15
  tests/test_symbols.py
@@ -0,0 +1,8 @@
1
+ matplotlib>=3.5
2
+ numpy>=1.21
3
+ seaborn>=0.11.2
4
+
5
+ [dev]
6
+ ruff
7
+ build
8
+ twine
@@ -0,0 +1,61 @@
1
+ import os
2
+ import tempfile
3
+ import unittest
4
+ from pathlib import Path
5
+
6
+ os.environ.setdefault("MPLBACKEND", "Agg")
7
+
8
+ from matplotlib import pyplot as plt # noqa: E402
9
+
10
+ from labplotlib import errorbar_plot, line_plot, scatter_with_fit # noqa: E402
11
+
12
+
13
+ class PlotTests(unittest.TestCase):
14
+ def tearDown(self):
15
+ plt.close("all")
16
+
17
+ def test_line_plot_returns_titled_figure(self):
18
+ fig = line_plot([1, 2, 3], [1, 4, 9], title="T", xlabel="x", ylabel="y", show=False)
19
+
20
+ ax = fig.axes[0]
21
+ self.assertEqual(ax.get_title(), "T")
22
+ self.assertEqual(ax.get_xlabel(), "x")
23
+
24
+ def test_saves_and_creates_directory(self):
25
+ with tempfile.TemporaryDirectory() as tmp:
26
+ target = Path(tmp) / "nested" / "out"
27
+ line_plot([1, 2], [1, 2], filename="p.png", save_directory=target, show=False)
28
+
29
+ self.assertTrue((target / "p.png").is_file())
30
+
31
+ def test_scatter_with_fit_has_two_artists(self):
32
+ fig = scatter_with_fit([1, 2, 3, 4], [2, 4, 6, 8], show=False)
33
+
34
+ ax = fig.axes[0]
35
+ self.assertEqual(len(ax.lines), 1)
36
+ self.assertEqual(len(ax.collections), 1)
37
+
38
+ def test_scatter_with_fit_validates_input(self):
39
+ with self.assertRaises(ValueError):
40
+ scatter_with_fit([1, 2, 3], [1, 2], show=False)
41
+ with self.assertRaises(ValueError):
42
+ scatter_with_fit([1, 2], [1, 2], degree=2, show=False)
43
+
44
+ def test_errorbar_plot(self):
45
+ fig = errorbar_plot([1, 2, 3], [1, 2, 3], yerr=[0.1, 0.1, 0.1], show=False)
46
+
47
+ self.assertEqual(len(fig.axes), 1)
48
+
49
+ def test_import_does_not_change_theme(self):
50
+ import subprocess
51
+ import sys
52
+
53
+ code = (
54
+ "import matplotlib as m; before = dict(m.rcParams); import labplotlib; "
55
+ "assert dict(m.rcParams) == before"
56
+ )
57
+ subprocess.run([sys.executable, "-c", code], check=True)
58
+
59
+
60
+ if __name__ == "__main__":
61
+ unittest.main()
@@ -0,0 +1,40 @@
1
+ import contextlib
2
+ import io
3
+ import unittest
4
+
5
+ from labplotlib import print_symbols, search, symbols
6
+
7
+
8
+ class SymbolTests(unittest.TestCase):
9
+ def test_search_returns_matching_symbols(self):
10
+ result = search("fraction_one")
11
+
12
+ self.assertIn("fraction_one_half_1_2", result)
13
+ self.assertNotIn("set_union", result)
14
+
15
+ def test_symbol_mappings_are_read_only(self):
16
+ with self.assertRaises(TypeError):
17
+ symbols["new_symbol"] = "x"
18
+
19
+ def test_search_is_case_insensitive(self):
20
+ self.assertEqual(dict(search("DELTA")), dict(search("delta")))
21
+ self.assertTrue(search("DELTA"))
22
+
23
+ def test_print_symbols_handles_multichar_and_astral(self):
24
+ buffer = io.StringIO()
25
+ with contextlib.redirect_stdout(buffer):
26
+ print_symbols(search("degree_celsius"))
27
+ print_symbols(search("set_universal"))
28
+
29
+ output = buffer.getvalue()
30
+ self.assertIn("\\u00b0 \\u0043", output)
31
+ self.assertIn("\\U0001d54c", output)
32
+
33
+ def test_renamed_symbols(self):
34
+ self.assertIn("plus_minus", symbols)
35
+ self.assertNotIn("+/-", symbols)
36
+ self.assertEqual(symbols["approximately_equal_to"], "≈")
37
+
38
+
39
+ if __name__ == "__main__":
40
+ unittest.main()
@@ -1,47 +0,0 @@
1
- # LabPlotLib
2
-
3
- LabPlotLib is a small Python library containing plotting-style helpers and a
4
- searchable collection of mathematical symbols.
5
-
6
- ## Installation
7
-
8
- Install the latest source checkout with pip:
9
-
10
- ```powershell
11
- python -m pip install .
12
- ```
13
-
14
- For development, install it in editable mode:
15
-
16
- ```powershell
17
- python -m pip install -e .
18
- ```
19
-
20
- ## Symbol utilities
21
-
22
- ```python
23
- from labplotlib import print_symbols, search, symbols
24
-
25
- print(symbols["set_union"])
26
- print(search("fraction"))
27
- print_symbols(search("fraction_one"))
28
- ```
29
-
30
- The `symbols` mapping is read-only. `search(name_part)` returns a read-only
31
- mapping containing symbol names that include `name_part`.
32
-
33
- Importing `labplotlib.Styling` applies the library's Seaborn plotting theme.
34
-
35
- ## Publishing
36
-
37
- Publishing is automated when a GitHub Release is published. Configure a PyPI
38
- trusted publisher for this repository with:
39
-
40
- - Owner and repository: the values for this GitHub project
41
- - Workflow: `.github/workflows/publish.yml`
42
- - Environment: `pypi`
43
-
44
- Then update the version in `pyproject.toml`, push the change, and create a
45
- GitHub Release with a matching version tag (for example, `v0.1.1`). The
46
- workflow runs the tests, builds the distributions, and publishes them without
47
- requiring a PyPI API token in GitHub secrets.
@@ -1,24 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=61"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "labplotlib"
7
- version = "0.1.0"
8
- description = "Plot styling helpers and searchable mathematical symbols."
9
- readme = "README.md"
10
- requires-python = ">=3.9"
11
- dependencies = [
12
- "matplotlib>=3.5",
13
- "seaborn>=0.11.2",
14
- ]
15
- classifiers = [
16
- "Programming Language :: Python :: 3",
17
- "Operating System :: OS Independent",
18
- ]
19
-
20
- [tool.setuptools]
21
- package-dir = {"" = "src"}
22
-
23
- [tool.setuptools.packages.find]
24
- where = ["src"]
@@ -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,3 +0,0 @@
1
- from .Symbols import print_symbols, search, symbols
2
-
3
- __all__ = ["symbols", "search", "print_symbols"]
@@ -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,2 +0,0 @@
1
- matplotlib>=3.5
2
- seaborn>=0.11.2
@@ -1,19 +0,0 @@
1
- import unittest
2
-
3
- from labplotlib import search, symbols
4
-
5
-
6
- class SymbolTests(unittest.TestCase):
7
- def test_search_returns_matching_symbols(self):
8
- result = search("fraction_one")
9
-
10
- self.assertIn("fraction_one_half_1_2", result)
11
- self.assertNotIn("set_union", result)
12
-
13
- def test_symbol_mappings_are_read_only(self):
14
- with self.assertRaises(TypeError):
15
- symbols["new_symbol"] = "x"
16
-
17
-
18
- if __name__ == "__main__":
19
- unittest.main()
File without changes