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

Skip to content

Commit baa5b59

Browse files
author
simonpf
committed
Added capstyle and joinstyle attributes to Collection class.
1 parent 201d536 commit baa5b59

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

lib/matplotlib/collections.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ class Collection(artist.Artist, cm.ScalarMappable):
5252
5353
prop[i % len(props)]
5454
55+
Exceptions are *capstyle* and *joinstyle* properties, these can
56+
only be set globally for the whole collection.
57+
5558
Keyword arguments and default values:
5659
5760
* *edgecolors*: None
5861
* *facecolors*: None
5962
* *linewidths*: None
63+
* *capstyle*: None
64+
* *joinstyle*: None
6065
* *antialiaseds*: None
6166
* *offsets*: None
6267
* *transOffset*: transforms.IdentityTransform()
@@ -104,6 +109,8 @@ def __init__(self,
104109
facecolors=None,
105110
linewidths=None,
106111
linestyles='solid',
112+
capstyle=None,
113+
joinstyle=None,
107114
antialiaseds=None,
108115
offsets=None,
109116
transOffset=None,
@@ -145,6 +152,16 @@ def __init__(self,
145152
self.set_offset_position(offset_position)
146153
self.set_zorder(zorder)
147154

155+
if capstyle:
156+
self.set_capstyle(capstyle)
157+
else:
158+
self._capstyle = None
159+
160+
if joinstyle:
161+
self.set_joinstyle(joinstyle)
162+
else:
163+
self._joinstyle = None
164+
148165
self._offsets = np.zeros((1, 2))
149166
self._uniform_offsets = None
150167
if offsets is not None:
@@ -304,6 +321,12 @@ def draw(self, renderer):
304321
extents.height < height):
305322
do_single_path_optimization = True
306323

324+
if self._joinstyle:
325+
gc.set_joinstyle(self._joinstyle)
326+
327+
if self._capstyle:
328+
gc.set_capstyle(self._capstyle)
329+
307330
if do_single_path_optimization:
308331
gc.set_foreground(tuple(edgecolors[0]))
309332
gc.set_linewidth(self._linewidths[0])
@@ -536,6 +559,42 @@ def set_linestyle(self, ls):
536559
self._linewidths, self._linestyles = self._bcast_lwls(
537560
self._us_lw, self._us_linestyles)
538561

562+
def set_capstyle(self, cs):
563+
"""
564+
Set the capstyle for the collection. The capstyle can
565+
only be set globally for all elements in the collection
566+
567+
Parameters
568+
----------
569+
cs : ['butt' | 'round' | 'projecting']
570+
The capstyle
571+
"""
572+
if cs in ('butt', 'round', 'projecting'):
573+
self._capstyle = cs
574+
else:
575+
raise ValueError('Unrecognized cap style. Found %s' % cs)
576+
577+
def get_capstyle(self):
578+
return self._capstyle
579+
580+
def set_joinstyle(self, js):
581+
"""
582+
Set the joinstyle for the collection. The joinstyle can only be
583+
set globally for all elements in the collection.
584+
585+
Parameters
586+
----------
587+
js : ['miter' | 'round' | 'bevel']
588+
The joinstyle
589+
"""
590+
if js in ('miter', 'round', 'bevel'):
591+
self._joinstyle = js
592+
else:
593+
raise ValueError('Unrecognized join style. Found %s' % js)
594+
595+
def get_joinstyle(self):
596+
return self._joinstyle
597+
539598
@staticmethod
540599
def _bcast_lwls(linewidths, dashes):
541600
'''Internal helper function to broadcast + scale ls/lw

0 commit comments

Comments
 (0)