Skip to content

Fix default return of Collection.get_{cap,join}style #25810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,16 @@ def set_capstyle(self, cs):
"""
self._capstyle = CapStyle(cs)

@_docstring.interpd
def get_capstyle(self):
return self._capstyle.name
"""
Return the cap style for the collection (for all its elements).

Returns
-------
%(CapStyle)s or None
"""
return self._capstyle.name if self._capstyle else None

@_docstring.interpd
def set_joinstyle(self, js):
Expand All @@ -655,8 +663,16 @@ def set_joinstyle(self, js):
"""
self._joinstyle = JoinStyle(js)

@_docstring.interpd
def get_joinstyle(self):
return self._joinstyle.name
"""
Return the join style for the collection (for all its elements).

Returns
-------
%(JoinStyle)s or None
"""
return self._joinstyle.name if self._joinstyle else None

@staticmethod
def _bcast_lwls(linewidths, dashes):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/collections.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class Collection(artist.Artist, cm.ScalarMappable):
def set_linewidth(self, lw: float | Sequence[float]) -> None: ...
def set_linestyle(self, ls: LineStyleType | Sequence[LineStyleType]) -> None: ...
def set_capstyle(self, cs: CapStyleType) -> None: ...
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
def get_capstyle(self) -> Literal["butt", "projecting", "round"] | None: ...
def set_joinstyle(self, js: JoinStyleType) -> None: ...
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
def get_joinstyle(self) -> Literal["miter", "round", "bevel"] | None: ...
def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ...
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...
def set_facecolor(self, c: ColorType | Sequence[ColorType]) -> None: ...
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ def test_set_wrong_linestyle():

@mpl.style.context('default')
def test_capstyle():
col = mcollections.PathCollection([])
assert col.get_capstyle() is None
col = mcollections.PathCollection([], capstyle='round')
assert col.get_capstyle() == 'round'
col.set_capstyle('butt')
Expand All @@ -633,6 +635,8 @@ def test_capstyle():

@mpl.style.context('default')
def test_joinstyle():
col = mcollections.PathCollection([])
assert col.get_joinstyle() is None
col = mcollections.PathCollection([], joinstyle='round')
assert col.get_joinstyle() == 'round'
col.set_joinstyle('miter')
Expand Down