Skip to content

Commit 3ca6f23

Browse files
authored
Merge pull request #25810 from QuLogic/fix-default-collection-style
Fix default return of Collection.get_{cap,join}style
2 parents 72888a1 + 4b99bc6 commit 3ca6f23

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/matplotlib/collections.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,16 @@ def set_capstyle(self, cs):
641641
"""
642642
self._capstyle = CapStyle(cs)
643643

644+
@_docstring.interpd
644645
def get_capstyle(self):
645-
return self._capstyle.name
646+
"""
647+
Return the cap style for the collection (for all its elements).
648+
649+
Returns
650+
-------
651+
%(CapStyle)s or None
652+
"""
653+
return self._capstyle.name if self._capstyle else None
646654

647655
@_docstring.interpd
648656
def set_joinstyle(self, js):
@@ -655,8 +663,16 @@ def set_joinstyle(self, js):
655663
"""
656664
self._joinstyle = JoinStyle(js)
657665

666+
@_docstring.interpd
658667
def get_joinstyle(self):
659-
return self._joinstyle.name
668+
"""
669+
Return the join style for the collection (for all its elements).
670+
671+
Returns
672+
-------
673+
%(JoinStyle)s or None
674+
"""
675+
return self._joinstyle.name if self._joinstyle else None
660676

661677
@staticmethod
662678
def _bcast_lwls(linewidths, dashes):

lib/matplotlib/collections.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class Collection(artist.Artist, cm.ScalarMappable):
5151
def set_linewidth(self, lw: float | Sequence[float]) -> None: ...
5252
def set_linestyle(self, ls: LineStyleType | Sequence[LineStyleType]) -> None: ...
5353
def set_capstyle(self, cs: CapStyleType) -> None: ...
54-
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
54+
def get_capstyle(self) -> Literal["butt", "projecting", "round"] | None: ...
5555
def set_joinstyle(self, js: JoinStyleType) -> None: ...
56-
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
56+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"] | None: ...
5757
def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ...
5858
def get_antialiased(self) -> NDArray[np.bool_]: ...
5959
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...

lib/matplotlib/tests/test_collections.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ def test_set_wrong_linestyle():
625625

626626
@mpl.style.context('default')
627627
def test_capstyle():
628+
col = mcollections.PathCollection([])
629+
assert col.get_capstyle() is None
628630
col = mcollections.PathCollection([], capstyle='round')
629631
assert col.get_capstyle() == 'round'
630632
col.set_capstyle('butt')
@@ -633,6 +635,8 @@ def test_capstyle():
633635

634636
@mpl.style.context('default')
635637
def test_joinstyle():
638+
col = mcollections.PathCollection([])
639+
assert col.get_joinstyle() is None
636640
col = mcollections.PathCollection([], joinstyle='round')
637641
assert col.get_joinstyle() == 'round'
638642
col.set_joinstyle('miter')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy