matplotlib-multicolored-line 0.2.0__tar.gz → 1.0.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.
Files changed (17) hide show
  1. {matplotlib_multicolored_line-0.2.0/src/matplotlib_multicolored_line.egg-info → matplotlib_multicolored_line-1.0.0}/PKG-INFO +9 -43
  2. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/README.md +4 -37
  3. matplotlib_multicolored_line-1.0.0/pyproject.toml +63 -0
  4. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line/__init__.py +1 -1
  5. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line/_main.py +45 -13
  6. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0/src/matplotlib_multicolored_line.egg-info}/PKG-INFO +9 -43
  7. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line.egg-info/SOURCES.txt +0 -1
  8. matplotlib_multicolored_line-1.0.0/tests/test_main.py +116 -0
  9. matplotlib_multicolored_line-0.2.0/pyproject.toml +0 -161
  10. matplotlib_multicolored_line-0.2.0/setup.py +0 -9
  11. matplotlib_multicolored_line-0.2.0/tests/test_main.py +0 -47
  12. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/LICENSE +0 -0
  13. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/setup.cfg +0 -0
  14. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line/py.typed +0 -0
  15. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line.egg-info/dependency_links.txt +0 -0
  16. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line.egg-info/requires.txt +0 -0
  17. {matplotlib_multicolored_line-0.2.0 → matplotlib_multicolored_line-1.0.0}/src/matplotlib_multicolored_line.egg-info/top_level.txt +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matplotlib-multicolored-line
3
- Version: 0.2.0
3
+ Version: 1.0.0
4
4
  Summary: Plot multicolored lines in Matplotlib
5
- Author-email: 34j <34j.95a2p@simplelogin.com>
5
+ Author: 34j
6
6
  License-Expression: CC0-1.0
7
7
  Project-URL: Bug Tracker, https://github.com/34j/matplotlib-multicolored-line/issues
8
8
  Project-URL: Changelog, https://github.com/34j/matplotlib-multicolored-line/blob/main/CHANGELOG.md
@@ -12,13 +12,12 @@ Classifier: Development Status :: 2 - Pre-Alpha
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Natural Language :: English
14
14
  Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3 :: Only
18
16
  Classifier: Programming Language :: Python :: 3.12
19
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
20
19
  Classifier: Topic :: Software Development :: Libraries
21
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.12
22
21
  Description-Content-Type: text/markdown
23
22
  License-File: LICENSE
24
23
  Requires-Dist: matplotlib>=3.9.4
@@ -33,19 +32,19 @@ Dynamic: license-file
33
32
  <a href="https://matplotlib-multicolored-line.readthedocs.io">
34
33
  <img src="https://img.shields.io/readthedocs/matplotlib-multicolored-line.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
35
34
  </a>
35
+ </p>
36
+ <p align="center">
36
37
  <a href="https://codecov.io/gh/34j/matplotlib-multicolored-line">
37
38
  <img src="https://img.shields.io/codecov/c/github/34j/matplotlib-multicolored-line.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
38
39
  </a>
39
- </p>
40
- <p align="center">
41
40
  <a href="https://github.com/astral-sh/uv">
42
41
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
43
42
  </a>
44
43
  <a href="https://github.com/astral-sh/ruff">
45
44
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
46
45
  </a>
47
- <a href="https://github.com/pre-commit/pre-commit">
48
- <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
46
+ <a href="https://github.com/j178/prek">
47
+ <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json" alt="prek">
49
48
  </a>
50
49
  </p>
51
50
  <p align="center">
@@ -104,36 +103,3 @@ fig.colorbar(lc)
104
103
  ```
105
104
 
106
105
  ![Result 2](https://raw.githubusercontent.com/34j/matplotlib-multicolored-line/main/example_multiple.jpg)
107
-
108
- ## Contributors ✨
109
-
110
- Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
111
-
112
- <!-- prettier-ignore-start -->
113
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
114
- <!-- prettier-ignore-start -->
115
- <!-- markdownlint-disable -->
116
- <table>
117
- <tbody>
118
- <tr>
119
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/34j"><img src="https://avatars.githubusercontent.com/u/55338215?v=4?s=80" width="80px;" alt="34j"/><br /><sub><b>34j</b></sub></a><br /><a href="https://github.com/34j/matplotlib-multicolored-line/commits?author=34j" title="Code">💻</a> <a href="#ideas-34j" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/34j/matplotlib-multicolored-line/commits?author=34j" title="Documentation">📖</a></td>
120
- </tr>
121
- </tbody>
122
- </table>
123
-
124
- <!-- markdownlint-restore -->
125
- <!-- prettier-ignore-end -->
126
-
127
- <!-- ALL-CONTRIBUTORS-LIST:END -->
128
- <!-- prettier-ignore-end -->
129
-
130
- This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
131
-
132
- ## Credits
133
-
134
- [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
135
-
136
- This package was created with
137
- [Copier](https://copier.readthedocs.io/) and the
138
- [browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)
139
- project template.
@@ -7,19 +7,19 @@
7
7
  <a href="https://matplotlib-multicolored-line.readthedocs.io">
8
8
  <img src="https://img.shields.io/readthedocs/matplotlib-multicolored-line.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
9
9
  </a>
10
+ </p>
11
+ <p align="center">
10
12
  <a href="https://codecov.io/gh/34j/matplotlib-multicolored-line">
11
13
  <img src="https://img.shields.io/codecov/c/github/34j/matplotlib-multicolored-line.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
12
14
  </a>
13
- </p>
14
- <p align="center">
15
15
  <a href="https://github.com/astral-sh/uv">
16
16
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
17
17
  </a>
18
18
  <a href="https://github.com/astral-sh/ruff">
19
19
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
20
20
  </a>
21
- <a href="https://github.com/pre-commit/pre-commit">
22
- <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
21
+ <a href="https://github.com/j178/prek">
22
+ <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json" alt="prek">
23
23
  </a>
24
24
  </p>
25
25
  <p align="center">
@@ -78,36 +78,3 @@ fig.colorbar(lc)
78
78
  ```
79
79
 
80
80
  ![Result 2](https://raw.githubusercontent.com/34j/matplotlib-multicolored-line/main/example_multiple.jpg)
81
-
82
- ## Contributors ✨
83
-
84
- Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
85
-
86
- <!-- prettier-ignore-start -->
87
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
88
- <!-- prettier-ignore-start -->
89
- <!-- markdownlint-disable -->
90
- <table>
91
- <tbody>
92
- <tr>
93
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/34j"><img src="https://avatars.githubusercontent.com/u/55338215?v=4?s=80" width="80px;" alt="34j"/><br /><sub><b>34j</b></sub></a><br /><a href="https://github.com/34j/matplotlib-multicolored-line/commits?author=34j" title="Code">💻</a> <a href="#ideas-34j" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/34j/matplotlib-multicolored-line/commits?author=34j" title="Documentation">📖</a></td>
94
- </tr>
95
- </tbody>
96
- </table>
97
-
98
- <!-- markdownlint-restore -->
99
- <!-- prettier-ignore-end -->
100
-
101
- <!-- ALL-CONTRIBUTORS-LIST:END -->
102
- <!-- prettier-ignore-end -->
103
-
104
- This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
105
-
106
- ## Credits
107
-
108
- [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
109
-
110
- This package was created with
111
- [Copier](https://copier.readthedocs.io/) and the
112
- [browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)
113
- project template.
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ build-backend = "setuptools.build_meta"
3
+ requires = [ "setuptools>=77.0.3" ]
4
+
5
+ [project]
6
+ name = "matplotlib-multicolored-line"
7
+ version = "1.0.0"
8
+ description = "Plot multicolored lines in Matplotlib"
9
+ readme = "README.md"
10
+ license = "CC0-1.0"
11
+ authors = [
12
+ { name = "34j" },
13
+ ]
14
+ requires-python = ">=3.12"
15
+ classifiers = [
16
+ "Development Status :: 2 - Pre-Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Natural Language :: English",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Topic :: Software Development :: Libraries",
25
+ ]
26
+ dependencies = [
27
+ "matplotlib>=3.9.4",
28
+ ]
29
+ urls."Bug Tracker" = "https://github.com/34j/matplotlib-multicolored-line/issues"
30
+ urls.Changelog = "https://github.com/34j/matplotlib-multicolored-line/blob/main/CHANGELOG.md"
31
+ urls.documentation = "https://matplotlib-multicolored-line.readthedocs.io"
32
+ urls.repository = "https://github.com/34j/matplotlib-multicolored-line"
33
+
34
+ [dependency-groups]
35
+ dev = [
36
+ "coverage",
37
+ "packaging-34j[test]",
38
+ "pytest",
39
+ "pytest-cov",
40
+ "ty",
41
+ ]
42
+ docs = [
43
+ "packaging-34j[docs]",
44
+ ]
45
+
46
+ [tool.ruff]
47
+ extend = ".venv/ruff.toml"
48
+ lint.ignore = [
49
+ "A001", # Built-in name shadowed by Sphinx configuration.
50
+ "C901", # The plotting API keeps its input-shape branches together.
51
+ "D401", # Preserve the existing Sphinx callback docstring.
52
+ "DOC501", # Existing public API documents its raised ValueError behavior.
53
+ "NPY002", # Preserve NumPy's global random helpers in visual test fixtures.
54
+ "PLR2004", # Shape dimensions are intentionally compared with literals.
55
+ "PT006", # Keep the existing readable parametrization declaration.
56
+ "TC002", # Runtime imports are required by Matplotlib annotations.
57
+ ]
58
+
59
+ [tool.pyproject-fmt]
60
+ max_supported_python = "3.14"
61
+
62
+ [tool.ty]
63
+ terminal.error-on-warning = true
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.0"
1
+ __version__ = "0.3.0"
2
2
  from ._main import colored_line
3
3
 
4
4
  __all__ = ["colored_line"]
@@ -31,8 +31,14 @@ def colored_line(
31
31
  *args : array-like
32
32
  The horizontal and vertical coordinates of the data points
33
33
  of shape (N,) or (N, m).
34
- c : array-like
35
- The color values, which should be the same size as x and y.
34
+ c : array-like or array-like of color, optional
35
+ The line values. Possible values:
36
+
37
+ - array-like of numbers of shape (N,) or (N, m), to be mapped to
38
+ colors using cmap and norm.
39
+ - array-like of numbers of shape (N, m, 3) or (N, m, 4), where the
40
+ last dimension is RGB or RGBA.
41
+ - array-like of colors of shape (N,) or (N, m).
36
42
  ax : matplotlib.axes.Axes, optional
37
43
  The axes to plot on. If not provided, the current axes will be used.
38
44
  start : array-like, optional
@@ -52,30 +58,57 @@ def colored_line(
52
58
  The generated line collection representing the colored line.
53
59
 
54
60
  """
55
- if "array" in kwargs:
56
- warnings.warn(
57
- 'The provided "array" keyword argument will be overridden',
58
- UserWarning,
59
- stacklevel=2,
60
- )
61
+ for key in ["array", "colors"]:
62
+ if key in kwargs:
63
+ warnings.warn(
64
+ f'The provided "{key}" keyword argument will be overridden',
65
+ UserWarning,
66
+ stacklevel=2,
67
+ )
61
68
 
62
69
  # parse args
63
70
  if len(args) == 1:
64
- y = args[0]
71
+ y = np.asarray(args[0])
65
72
  x = np.arange(len(y))
66
73
  elif len(args) == 2:
67
- x, y = args
74
+ x = np.asarray(args[0])
75
+ y = np.asarray(args[1])
68
76
  else:
69
77
  raise ValueError("Invalid number of arguments. Provide either x and y or just y.")
70
78
 
71
79
  # ensure x, y, c are 1D or 2D arrays
72
- x, y, c = map(np.asarray, (x, y, c))
80
+ c = np.asarray(c)
81
+ start = np.asarray(start)
82
+ end = np.asarray(end)
73
83
  if x.ndim == 1:
74
84
  x = x[:, None]
85
+ elif x.ndim == 2:
86
+ pass
87
+ else:
88
+ raise ValueError(f"{x.ndim=} should be 1 or 2")
75
89
  if y.ndim == 1:
76
90
  y = y[:, None]
91
+ elif y.ndim == 2:
92
+ pass
93
+ else:
94
+ raise ValueError(f"{y.ndim=} should be 1 or 2")
77
95
  x, y = np.broadcast_arrays(x, y)
78
96
 
97
+ if c.ndim == 1:
98
+ c = c[:, None]
99
+ if c.ndim == 2:
100
+ c = np.broadcast_to(c, x.shape).reshape((-1,))
101
+ if np.issubdtype(c.dtype, np.number):
102
+ kwargs["array"] = c
103
+ else:
104
+ kwargs["colors"] = c
105
+ elif c.ndim == 3:
106
+ c = np.broadcast_to(c, (*x.shape, c.shape[-1])).reshape((-1, c.shape[-1]))
107
+ c = [tuple(c[i]) for i in range(c.shape[0])]
108
+ kwargs["colors"] = c
109
+ else:
110
+ raise ValueError(f"{c.ndim=} should be 2 or 3")
111
+
79
112
  # (N, m, 2)
80
113
  xy = np.stack((x, y), axis=-1)
81
114
  # (N, m, 2)
@@ -88,8 +121,7 @@ def colored_line(
88
121
  segments = np.stack((xy_start, xy, xy_end), axis=-2)
89
122
  segments = np.reshape(segments, (-1, segments.shape[-2], segments.shape[-1]))
90
123
 
91
- kwargs["array"] = c.reshape(-1)
92
- lc = LineCollection(segments, **kwargs)
124
+ lc = LineCollection(segments.tolist(), **kwargs)
93
125
 
94
126
  # Plot the line collection to the axes
95
127
  ax = ax or plt.gca()
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matplotlib-multicolored-line
3
- Version: 0.2.0
3
+ Version: 1.0.0
4
4
  Summary: Plot multicolored lines in Matplotlib
5
- Author-email: 34j <34j.95a2p@simplelogin.com>
5
+ Author: 34j
6
6
  License-Expression: CC0-1.0
7
7
  Project-URL: Bug Tracker, https://github.com/34j/matplotlib-multicolored-line/issues
8
8
  Project-URL: Changelog, https://github.com/34j/matplotlib-multicolored-line/blob/main/CHANGELOG.md
@@ -12,13 +12,12 @@ Classifier: Development Status :: 2 - Pre-Alpha
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Natural Language :: English
14
14
  Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3 :: Only
18
16
  Classifier: Programming Language :: Python :: 3.12
19
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
20
19
  Classifier: Topic :: Software Development :: Libraries
21
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.12
22
21
  Description-Content-Type: text/markdown
23
22
  License-File: LICENSE
24
23
  Requires-Dist: matplotlib>=3.9.4
@@ -33,19 +32,19 @@ Dynamic: license-file
33
32
  <a href="https://matplotlib-multicolored-line.readthedocs.io">
34
33
  <img src="https://img.shields.io/readthedocs/matplotlib-multicolored-line.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
35
34
  </a>
35
+ </p>
36
+ <p align="center">
36
37
  <a href="https://codecov.io/gh/34j/matplotlib-multicolored-line">
37
38
  <img src="https://img.shields.io/codecov/c/github/34j/matplotlib-multicolored-line.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
38
39
  </a>
39
- </p>
40
- <p align="center">
41
40
  <a href="https://github.com/astral-sh/uv">
42
41
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
43
42
  </a>
44
43
  <a href="https://github.com/astral-sh/ruff">
45
44
  <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
46
45
  </a>
47
- <a href="https://github.com/pre-commit/pre-commit">
48
- <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
46
+ <a href="https://github.com/j178/prek">
47
+ <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json" alt="prek">
49
48
  </a>
50
49
  </p>
51
50
  <p align="center">
@@ -104,36 +103,3 @@ fig.colorbar(lc)
104
103
  ```
105
104
 
106
105
  ![Result 2](https://raw.githubusercontent.com/34j/matplotlib-multicolored-line/main/example_multiple.jpg)
107
-
108
- ## Contributors ✨
109
-
110
- Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
111
-
112
- <!-- prettier-ignore-start -->
113
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
114
- <!-- prettier-ignore-start -->
115
- <!-- markdownlint-disable -->
116
- <table>
117
- <tbody>
118
- <tr>
119
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/34j"><img src="https://avatars.githubusercontent.com/u/55338215?v=4?s=80" width="80px;" alt="34j"/><br /><sub><b>34j</b></sub></a><br /><a href="https://github.com/34j/matplotlib-multicolored-line/commits?author=34j" title="Code">💻</a> <a href="#ideas-34j" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/34j/matplotlib-multicolored-line/commits?author=34j" title="Documentation">📖</a></td>
120
- </tr>
121
- </tbody>
122
- </table>
123
-
124
- <!-- markdownlint-restore -->
125
- <!-- prettier-ignore-end -->
126
-
127
- <!-- ALL-CONTRIBUTORS-LIST:END -->
128
- <!-- prettier-ignore-end -->
129
-
130
- This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
131
-
132
- ## Credits
133
-
134
- [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
135
-
136
- This package was created with
137
- [Copier](https://copier.readthedocs.io/) and the
138
- [browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)
139
- project template.
@@ -1,7 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
- setup.py
5
4
  src/matplotlib_multicolored_line/__init__.py
6
5
  src/matplotlib_multicolored_line/_main.py
7
6
  src/matplotlib_multicolored_line/py.typed
@@ -0,0 +1,116 @@
1
+ from collections.abc import Sequence
2
+ from pathlib import Path
3
+
4
+ import matplotlib.pyplot as plt
5
+ import numpy as np
6
+ import pytest
7
+ from numpy.typing import ArrayLike
8
+
9
+ from matplotlib_multicolored_line import colored_line
10
+
11
+ plt.switch_backend("Agg")
12
+
13
+ CACHE_PATH = Path(__file__).parent / ".cache"
14
+
15
+
16
+ @pytest.fixture(autouse=True)
17
+ def setup_cache() -> None:
18
+ CACHE_PATH.mkdir(parents=True, exist_ok=True)
19
+
20
+
21
+ t = np.linspace(-7.4, -0.5, 200)
22
+
23
+
24
+ @pytest.mark.parametrize(
25
+ "name, args, c",
26
+ [
27
+ ("notebook1", (0.9 * np.sin(t), 0.5 * np.sin(t)), t),
28
+ ("notebook2", ([0, 1, 2, 3, 4], [0, 1, 2, 1, 1]), [1, 2, 3, 4, 5]),
29
+ ("singley", (np.random.normal(size=(5,)),), np.random.normal(size=(5,))),
30
+ ("singley.rgb", (np.random.normal(size=(5,)),), np.random.normal(size=(5, 1, 3))),
31
+ ("singley.rgba", (np.random.normal(size=(5,)),), np.random.normal(size=(5, 1, 4))),
32
+ (
33
+ "singley.colors",
34
+ (np.random.normal(size=(5,)),),
35
+ np.random.choice(["black", "red"], size=(5,)),
36
+ ),
37
+ (
38
+ "singlexy",
39
+ (
40
+ np.random.normal(size=(5,)),
41
+ np.random.normal(size=(5,)),
42
+ ),
43
+ np.random.normal(size=(5,)),
44
+ ),
45
+ (
46
+ "singlexy.rgb",
47
+ (
48
+ np.random.normal(size=(5,)),
49
+ np.random.normal(size=(5,)),
50
+ ),
51
+ np.random.normal(size=(5, 1, 3)),
52
+ ),
53
+ (
54
+ "singlexy.rgba",
55
+ (
56
+ np.random.normal(size=(5,)),
57
+ np.random.normal(size=(5,)),
58
+ ),
59
+ np.random.normal(size=(5, 1, 4)),
60
+ ),
61
+ (
62
+ "singlexy.colors",
63
+ (
64
+ np.random.normal(size=(5,)),
65
+ np.random.normal(size=(5,)),
66
+ ),
67
+ np.random.choice(["black", "red"], size=(5,)),
68
+ ),
69
+ ("multiy", (np.random.normal(size=(5, 2)),), np.random.normal(size=(5, 2))),
70
+ ("multiy.rgb", (np.random.normal(size=(5, 2)),), np.random.uniform(size=(5, 2, 3))),
71
+ ("multiy.rgba", (np.random.normal(size=(5, 2)),), np.random.uniform(size=(5, 2, 4))),
72
+ (
73
+ "multiy.colors",
74
+ (np.random.normal(size=(5, 2)),),
75
+ np.random.choice(["black", "red"], size=(5, 2)),
76
+ ),
77
+ (
78
+ "multixy",
79
+ (
80
+ np.random.normal(size=(5, 2)),
81
+ np.random.normal(size=(5, 2)),
82
+ ),
83
+ np.random.normal(size=(5, 2)),
84
+ ),
85
+ (
86
+ "multixy.rgb",
87
+ (
88
+ np.random.normal(size=(5, 2)),
89
+ np.random.normal(size=(5, 2)),
90
+ ),
91
+ np.random.uniform(size=(5, 2, 3)),
92
+ ),
93
+ (
94
+ "multixy.rgba",
95
+ (
96
+ np.random.normal(size=(5, 2)),
97
+ np.random.normal(size=(5, 2)),
98
+ ),
99
+ np.random.uniform(size=(5, 2, 4)),
100
+ ),
101
+ (
102
+ "multixy.colors",
103
+ (
104
+ np.random.normal(size=(5, 2)),
105
+ np.random.normal(size=(5, 2)),
106
+ ),
107
+ np.random.choice(["black", "red"], size=(5, 2)),
108
+ ),
109
+ ],
110
+ )
111
+ def test_multicolor(name: str, args: Sequence[ArrayLike], c: ArrayLike) -> None:
112
+ fig, ax = plt.subplots()
113
+ lc = colored_line(*args, c=c, ax=ax, linewidth=10)
114
+ if "rgb" not in name:
115
+ fig.colorbar(lc)
116
+ fig.savefig(CACHE_PATH / f"example.{name}.jpg")
@@ -1,161 +0,0 @@
1
- [build-system]
2
- build-backend = "setuptools.build_meta"
3
- requires = [ "setuptools" ]
4
-
5
- [project]
6
- name = "matplotlib-multicolored-line"
7
- version = "0.2.0"
8
- description = "Plot multicolored lines in Matplotlib"
9
- readme = "README.md"
10
- license = "CC0-1.0"
11
- authors = [
12
- { name = "34j", email = "34j.95a2p@simplelogin.com" },
13
- ]
14
- requires-python = ">=3.9"
15
- classifiers = [
16
- "Development Status :: 2 - Pre-Alpha",
17
- "Intended Audience :: Developers",
18
- "Natural Language :: English",
19
- "Operating System :: OS Independent",
20
- "Programming Language :: Python :: 3.9",
21
- "Programming Language :: Python :: 3.10",
22
- "Programming Language :: Python :: 3.11",
23
- "Programming Language :: Python :: 3.12",
24
- "Programming Language :: Python :: 3.13",
25
- "Topic :: Software Development :: Libraries",
26
- ]
27
-
28
- dependencies = [
29
- "matplotlib>=3.9.4",
30
- ]
31
- urls."Bug Tracker" = "https://github.com/34j/matplotlib-multicolored-line/issues"
32
- urls.Changelog = "https://github.com/34j/matplotlib-multicolored-line/blob/main/CHANGELOG.md"
33
- urls.documentation = "https://matplotlib-multicolored-line.readthedocs.io"
34
- urls.repository = "https://github.com/34j/matplotlib-multicolored-line"
35
-
36
- [dependency-groups]
37
- dev = [
38
- "pytest>=8,<9",
39
- "pytest-cov>=6,<7",
40
- ]
41
- docs = [
42
- "furo>=2023.5.20; python_version>='3.11'",
43
- "myst-parser>=0.16; python_version>='3.11'",
44
- "sphinx>=4; python_version>='3.11'",
45
- "sphinx-autobuild>=2024,<2025; python_version>='3.11'",
46
- ]
47
-
48
- [tool.ruff]
49
- line-length = 100
50
- lint.select = [
51
- "B", # flake8-bugbear
52
- "D", # flake8-docstrings
53
- "C4", # flake8-comprehensions
54
- "S", # flake8-bandit
55
- "F", # pyflake
56
- "E", # pycodestyle
57
- "W", # pycodestyle
58
- "UP", # pyupgrade
59
- "I", # isort
60
- "RUF", # ruff specific
61
- ]
62
- lint.ignore = [
63
- "D203", # 1 blank line required before class docstring
64
- "D212", # Multi-line docstring summary should start at the first line
65
- "D100", # Missing docstring in public module
66
- "D104", # Missing docstring in public package
67
- "D107", # Missing docstring in `__init__`
68
- "D401", # First line of docstring should be in imperative mood
69
- ]
70
- lint.per-file-ignores."conftest.py" = [ "D100" ]
71
- lint.per-file-ignores."docs/conf.py" = [ "D100" ]
72
- lint.per-file-ignores."setup.py" = [ "D100" ]
73
- lint.per-file-ignores."tests/**/*" = [
74
- "D100",
75
- "D101",
76
- "D102",
77
- "D103",
78
- "D104",
79
- "S101",
80
- ]
81
- lint.isort.known-first-party = [ "matplotlib_multicolored_line", "tests" ]
82
-
83
- [tool.pytest.ini_options]
84
- addopts = """\
85
- -v
86
- -Wdefault
87
- --cov=matplotlib_multicolored_line
88
- --cov-report=term
89
- --cov-report=xml
90
- """
91
- pythonpath = [ "src" ]
92
-
93
- [tool.coverage.run]
94
- branch = true
95
-
96
- [tool.coverage.report]
97
- exclude_lines = [
98
- "pragma: no cover",
99
- "@overload",
100
- "if TYPE_CHECKING",
101
- "raise NotImplementedError",
102
- 'if __name__ == "__main__":',
103
- ]
104
-
105
- [tool.mypy]
106
- check_untyped_defs = true
107
- disallow_any_generics = true
108
- disallow_incomplete_defs = true
109
- disallow_untyped_defs = true
110
- mypy_path = "src/"
111
- no_implicit_optional = true
112
- show_error_codes = true
113
- warn_unreachable = true
114
- warn_unused_ignores = true
115
- exclude = [
116
- 'docs/.*',
117
- 'setup.py',
118
- ]
119
-
120
- [[tool.mypy.overrides]]
121
- module = "tests.*"
122
- allow_untyped_defs = true
123
-
124
- [[tool.mypy.overrides]]
125
- module = "docs.*"
126
- ignore_errors = true
127
-
128
- [tool.semantic_release]
129
- version_toml = [ "pyproject.toml:project.version" ]
130
- version_variables = [
131
- "src/matplotlib_multicolored_line/__init__.py:__version__",
132
- "docs/conf.py:release",
133
- ]
134
- build_command = """
135
- pip install uv
136
- uv lock
137
- git add uv.lock
138
- uv build
139
- """
140
-
141
- [tool.semantic_release.changelog]
142
- exclude_commit_patterns = [
143
- '''chore(?:\([^)]*?\))?: .+''',
144
- '''ci(?:\([^)]*?\))?: .+''',
145
- '''refactor(?:\([^)]*?\))?: .+''',
146
- '''style(?:\([^)]*?\))?: .+''',
147
- '''test(?:\([^)]*?\))?: .+''',
148
- '''build\((?!deps\): .+)''',
149
- '''Merged? .*''',
150
- '''Initial [Cc]ommit.*''', # codespell:ignore
151
- ]
152
-
153
- [tool.semantic_release.changelog.environment]
154
- keep_trailing_newline = true
155
-
156
- [tool.semantic_release.branches.main]
157
- match = "main"
158
-
159
- [tool.semantic_release.branches.noop]
160
- match = "(?!main$)"
161
- prerelease = true
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- # This is a shim to allow GitHub to detect the package, build is done with uv
4
- # Taken from https://github.com/Textualize/rich
5
-
6
- import setuptools
7
-
8
- if __name__ == "__main__":
9
- setuptools.setup(name="matplotlib-multicolored-line")
@@ -1,47 +0,0 @@
1
- from pathlib import Path
2
-
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
- import pytest
6
-
7
- from matplotlib_multicolored_line import colored_line
8
-
9
- CACHE_PATH = Path(__file__).parent / ".cache"
10
-
11
-
12
- @pytest.fixture(autouse=True)
13
- def setup_cache() -> None:
14
- CACHE_PATH.mkdir(parents=True, exist_ok=True)
15
-
16
-
17
- def test_main() -> None:
18
- t = np.linspace(-7.4, -0.5, 200)
19
- x = 0.9 * np.sin(t)
20
- y = 0.9 * np.cos(1.6 * t)
21
-
22
- fig, ax = plt.subplots()
23
- lc = colored_line(x, y, c=t, ax=ax, linewidth=10)
24
- fig.colorbar(lc)
25
- fig.savefig(CACHE_PATH / "example.jpg")
26
-
27
-
28
- def test_main_small() -> None:
29
- x = [0, 1, 2, 3, 4]
30
- y = [0, 1, 2, 1, 1]
31
- c = [1, 2, 3, 4, 5]
32
-
33
- fig, ax = plt.subplots()
34
- lc = colored_line(x, y, c=c, ax=ax, linewidth=10)
35
- fig.colorbar(lc)
36
- fig.savefig(CACHE_PATH / "example_small.jpg")
37
-
38
-
39
- def test_multiple() -> None:
40
- np.random.seed(0)
41
- y = np.random.normal(size=(5, 2))
42
- c = np.random.normal(size=(5, 2))
43
-
44
- fig, ax = plt.subplots()
45
- lc = colored_line(y, c=c, ax=ax, linewidth=10)
46
- fig.colorbar(lc)
47
- fig.savefig(CACHE_PATH / "example_multiple.jpg")