Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f95e9b6

Browse files
committed
Accept strings for {Cap,Join}Style in MarkerStyle
When these Enum classes were added in matplotlib#18544, they were supposed to be for documentation only. To that end, matplotlib#22055 was a followup that ensured that only the strings were exposed from the getter side. However, when user-supplied cap/join style were added in matplotlib#20914, they were only for the Enum type instead of the string, so correctly allow strings here as well. Also, specifically type hint the return values as literals, as was done in matplotlib#25719.
1 parent d464cbf commit f95e9b6

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

lib/matplotlib/markers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ def __init__(self, marker,
241241
Transform that will be combined with the native transform of the
242242
marker.
243243
244-
capstyle : CapStyle, default: None
244+
capstyle : `.CapStyle` or %(CapStyle)s, default: None
245245
Cap style that will override the default cap style of the marker.
246246
247-
joinstyle : JoinStyle, default: None
247+
joinstyle : `.JoinStyle` or %(JoinStyle)s, default: None
248248
Join style that will override the default join style of the marker.
249249
"""
250250
self._marker_function = None
251251
self._user_transform = transform
252-
self._user_capstyle = capstyle
253-
self._user_joinstyle = joinstyle
252+
self._user_capstyle = CapStyle(capstyle) if capstyle is not None else None
253+
self._user_joinstyle = JoinStyle(joinstyle) if joinstyle is not None else None
254254
self._set_fillstyle(fillstyle)
255255
self._set_marker(marker)
256256

lib/matplotlib/markers.pyi

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from ._enums import CapStyle, JoinStyle
1+
from typing import Literal
2+
23
from .path import Path
34
from .transforms import Affine2D, Transform
45

56
from numpy.typing import ArrayLike
6-
from .typing import FillStyleType
7+
from .typing import CapStyleType, FillStyleType, JoinStyleType
78

89
TICKLEFT: int
910
TICKRIGHT: int
@@ -28,16 +29,14 @@ class MarkerStyle:
2829
marker: str | ArrayLike | Path | MarkerStyle | None,
2930
fillstyle: FillStyleType | None = ...,
3031
transform: Transform | None = ...,
31-
capstyle: CapStyle | None = ...,
32-
joinstyle: JoinStyle | None = ...,
32+
capstyle: CapStyleType | None = ...,
33+
joinstyle: JoinStyleType | None = ...,
3334
) -> None: ...
3435
def __bool__(self) -> bool: ...
3536
def is_filled(self) -> bool: ...
36-
def get_fillstyle(
37-
self,
38-
) -> FillStyleType: ...
39-
def get_joinstyle(self) -> JoinStyle: ...
40-
def get_capstyle(self) -> CapStyle: ...
37+
def get_fillstyle(self) -> FillStyleType: ...
38+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
39+
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
4140
def get_marker(self) -> str | ArrayLike | Path | MarkerStyle | None: ...
4241
def get_path(self) -> Path: ...
4342
def get_transform(self) -> Transform: ...

lib/matplotlib/tests/test_marker.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,16 @@ def test_marker_init_transforms():
207207

208208
def test_marker_init_joinstyle():
209209
marker = markers.MarkerStyle("*")
210-
jstl = markers.JoinStyle.round
211-
styled_marker = markers.MarkerStyle("*", joinstyle=jstl)
212-
assert styled_marker.get_joinstyle() == jstl
213-
assert marker.get_joinstyle() != jstl
210+
styled_marker = markers.MarkerStyle("*", joinstyle="round")
211+
assert styled_marker.get_joinstyle() == "round"
212+
assert marker.get_joinstyle() != "round"
214213

215214

216215
def test_marker_init_captyle():
217216
marker = markers.MarkerStyle("*")
218-
capstl = markers.CapStyle.round
219-
styled_marker = markers.MarkerStyle("*", capstyle=capstl)
220-
assert styled_marker.get_capstyle() == capstl
221-
assert marker.get_capstyle() != capstl
217+
styled_marker = markers.MarkerStyle("*", capstyle="round")
218+
assert styled_marker.get_capstyle() == "round"
219+
assert marker.get_capstyle() != "round"
222220

223221

224222
@pytest.mark.parametrize("marker,transform,expected", [

0 commit comments

Comments
 (0)