1717from . import (_path , artist , cbook , cm , colors as mcolors , docstring ,
1818 lines as mlines , path as mpath , transforms )
1919
20- CIRCLE_AREA_FACTOR = 1.0 / np .sqrt (np .pi )
21-
2220
2321@cbook ._define_aliases ({
2422 "antialiased" : ["antialiaseds" ],
@@ -58,7 +56,6 @@ class Collection(artist.Artist, cm.ScalarMappable):
5856 * *hatch*: None
5957 * *zorder*: 1
6058
61-
6259 *offsets* and *transOffset* are used to translate the patch after
6360 rendering (default no offsets). If offset_position is 'screen'
6461 (default) the offset is applied after the master transform has
@@ -207,12 +204,12 @@ def get_datalim(self, transData):
207204 return result
208205
209206 def get_window_extent (self , renderer ):
210- # TODO:check to ensure that this does not fail for
207+ # TODO: check to ensure that this does not fail for
211208 # cases other than scatter plot legend
212209 return self .get_datalim (transforms .IdentityTransform ())
213210
214211 def _prepare_points (self ):
215- """Point prep for drawing and hit testing"""
212+ # Helper for drawing and hit testing.
216213
217214 transform = self .get_transform ()
218215 transOffset = self .get_offset_transform ()
@@ -227,8 +224,7 @@ def _prepare_points(self):
227224 xs = self .convert_xunits (xs )
228225 ys = self .convert_yunits (ys )
229226 paths .append (mpath .Path (np .column_stack ([xs , ys ]), path .codes ))
230-
231- if offsets .size > 0 :
227+ if offsets .size :
232228 xs = self .convert_xunits (offsets [:, 0 ])
233229 ys = self .convert_yunits (offsets [:, 1 ])
234230 offsets = np .column_stack ([xs , ys ])
@@ -336,7 +332,8 @@ def draw(self, renderer):
336332 self .stale = False
337333
338334 def set_pickradius (self , pr ):
339- """Set the pick radius used for containment tests.
335+ """
336+ Set the pick radius used for containment tests.
340337
341338 Parameters
342339 ----------
@@ -352,8 +349,8 @@ def contains(self, mouseevent):
352349 """
353350 Test whether the mouse event occurred in the collection.
354351
355- Returns True | False, `` dict(ind=itemlist)``, where every
356- item in itemlist contains the event.
352+ Returns ``bool, dict(ind=itemlist)``, where every item in itemlist
353+ contains the event.
357354 """
358355 if callable (self ._contains ):
359356 return self ._contains (self , mouseevent )
@@ -430,8 +427,7 @@ def get_hatch(self):
430427
431428 def set_offsets (self , offsets ):
432429 """
433- Set the offsets for the collection. *offsets* can be a scalar
434- or a sequence.
430+ Set the offsets for the collection.
435431
436432 Parameters
437433 ----------
@@ -552,8 +548,7 @@ def set_linestyle(self, ls):
552548
553549 def set_capstyle (self , cs ):
554550 """
555- Set the capstyle for the collection. The capstyle can
556- only be set globally for all elements in the collection
551+ Set the capstyle for the collection (for all its elements).
557552
558553 Parameters
559554 ----------
@@ -570,8 +565,7 @@ def get_capstyle(self):
570565
571566 def set_joinstyle (self , js ):
572567 """
573- Set the joinstyle for the collection. The joinstyle can only be
574- set globally for all elements in the collection.
568+ Set the joinstyle for the collection (for all its elements).
575569
576570 Parameters
577571 ----------
@@ -588,28 +582,26 @@ def get_joinstyle(self):
588582
589583 @staticmethod
590584 def _bcast_lwls (linewidths , dashes ):
591- '''Internal helper function to broadcast + scale ls/lw
585+ """
586+ Internal helper function to broadcast + scale ls/lw
592587
593- In the collection drawing code the linewidth and linestyle are
594- cycled through as circular buffers (via v[i % len(v)]). Thus,
595- if we are going to scale the dash pattern at set time (not
596- draw time) we need to do the broadcasting now and expand both
597- lists to be the same length.
588+ In the collection drawing code, the linewidth and linestyle are cycled
589+ through as circular buffers (via ``v[i % len(v)]``). Thus, if we are
590+ going to scale the dash pattern at set time (not draw time) we need to
591+ do the broadcasting now and expand both lists to be the same length.
598592
599593 Parameters
600594 ----------
601595 linewidths : list
602596 line widths of collection
603-
604597 dashes : list
605598 dash specification (offset, (dash pattern tuple))
606599
607600 Returns
608601 -------
609602 linewidths, dashes : list
610603 Will be the same length, dashes are scaled by paired linewidth
611-
612- '''
604+ """
613605 if mpl .rcParams ['_internal.classic_mode' ]:
614606 return linewidths , dashes
615607 # make sure they are the same length so we can zip them
@@ -723,26 +715,20 @@ def _set_edgecolor(self, c):
723715
724716 def set_edgecolor (self , c ):
725717 """
726- Set the edgecolor(s) of the collection. *c* can be a
727- matplotlib color spec (all patches have same color), or a
728- sequence of specs; if it is a sequence the patches will
729- cycle through the sequence.
730-
731- If *c* is 'face', the edge color will always be the same as
732- the face color. If it is 'none', the patch boundary will not
733- be drawn.
718+ Set the edgecolor(s) of the collection.
734719
735720 Parameters
736721 ----------
737- c : color or sequence of colors
722+ c : color or sequence of colors or 'face'
723+ The collection edgecolor(s). If a sequence, the patches cycle
724+ through it. If 'face', match the facecolor.
738725 """
739726 self ._original_edgecolor = c
740727 self ._set_edgecolor (c )
741728
742729 def set_alpha (self , alpha ):
743730 """
744- Set the alpha tranparencies of the collection. *alpha* must be
745- a float or *None*.
731+ Set the alpha tranparencies of the collection.
746732
747733 Parameters
748734 ----------
@@ -765,10 +751,7 @@ def get_linestyle(self):
765751 return self ._linestyles
766752
767753 def update_scalarmappable (self ):
768- """
769- If the scalar mappable array is not none, update colors
770- from scalar data
771- """
754+ """Update colors from the scalar mappable array, if it is not None."""
772755 if self ._A is None :
773756 return
774757 if self ._A .ndim > 1 :
@@ -861,7 +844,6 @@ def set_sizes(self, sizes, dpi=72.0):
861844 sizes : ndarray or None
862845 The size to set for each element of the collection. The
863846 value is the 'area' of the element.
864-
865847 dpi : float
866848 The dpi of the canvas. Defaults to 72.0.
867849 """
@@ -963,7 +945,7 @@ def set_verts(self, verts, closed=True):
963945 set_paths = set_verts
964946
965947 def set_verts_and_codes (self , verts , codes ):
966- ''' This allows one to initialize vertices with path codes.'''
948+ """ This allows one to initialize vertices with path codes."""
967949 if len (verts ) != len (codes ):
968950 raise ValueError ("'codes' must be a 1D list or array "
969951 "with the same length of 'verts'" )
@@ -1025,9 +1007,9 @@ def span_where(x, ymin, ymax, where, **kwargs):
10251007
10261008class RegularPolyCollection (_CollectionWithSizes ):
10271009 """Draw a collection of regular polygons with *numsides*."""
1028- _path_generator = mpath .Path .unit_regular_polygon
10291010
1030- _factor = CIRCLE_AREA_FACTOR
1011+ _path_generator = mpath .Path .unit_regular_polygon
1012+ _factor = np .pi ** (- 1 / 2 )
10311013
10321014 @docstring .dedent_interpd
10331015 def __init__ (self ,
@@ -1089,16 +1071,12 @@ def draw(self, renderer):
10891071
10901072
10911073class StarPolygonCollection (RegularPolyCollection ):
1092- """
1093- Draw a collection of regular stars with *numsides* points."""
1094-
1074+ """Draw a collection of regular stars with *numsides* points."""
10951075 _path_generator = mpath .Path .unit_regular_star
10961076
10971077
10981078class AsteriskPolygonCollection (RegularPolyCollection ):
1099- """
1100- Draw a collection of regular asterisks with *numsides* points."""
1101-
1079+ """Draw a collection of regular asterisks with *numsides* points."""
11021080 _path_generator = mpath .Path .unit_regular_asterisk
11031081
11041082
@@ -1295,13 +1273,13 @@ def get_color(self):
12951273
12961274
12971275class EventCollection (LineCollection ):
1298- '''
1276+ """
12991277 A collection of discrete events.
13001278
13011279 The events are given by a 1-dimensional array, usually the position of
13021280 something along an axis, such as time or length. They do not have an
13031281 amplitude and are displayed as vertical or horizontal parallel bars.
1304- '''
1282+ """
13051283
13061284 _edge_default = True
13071285
@@ -1542,10 +1520,9 @@ def get_color(self):
15421520
15431521
15441522class CircleCollection (_CollectionWithSizes ):
1545- """
1546- A collection of circles, drawn using splines.
1547- """
1548- _factor = CIRCLE_AREA_FACTOR
1523+ """A collection of circles, drawn using splines."""
1524+
1525+ _factor = np .pi ** (- 1 / 2 )
15491526
15501527 @docstring .dedent_interpd
15511528 def __init__ (self , sizes , ** kwargs ):
@@ -1562,9 +1539,8 @@ def __init__(self, sizes, **kwargs):
15621539
15631540
15641541class EllipseCollection (Collection ):
1565- """
1566- A collection of ellipses, drawn using splines.
1567- """
1542+ """A collection of ellipses, drawn using splines."""
1543+
15681544 @docstring .dedent_interpd
15691545 def __init__ (self , widths , heights , angles , units = 'points' , ** kwargs ):
15701546 """
@@ -1607,9 +1583,8 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
16071583 self ._paths = [mpath .Path .unit_circle ()]
16081584
16091585 def _set_transforms (self ):
1610- """
1611- Calculate transforms immediately before drawing.
1612- """
1586+ """Calculate transforms immediately before drawing."""
1587+
16131588 ax = self .axes
16141589 fig = self .figure
16151590
@@ -1712,11 +1687,9 @@ def set_paths(self, patches):
17121687
17131688class TriMesh (Collection ):
17141689 """
1715- Class for the efficient drawing of a triangular mesh using
1716- Gouraud shading.
1690+ Class for the efficient drawing of a triangular mesh using Gouraud shading.
17171691
1718- A triangular mesh is a :class:`~matplotlib.tri.Triangulation`
1719- object.
1692+ A triangular mesh is a `~matplotlib.tri.Triangulation` object.
17201693 """
17211694 def __init__ (self , triangulation , ** kwargs ):
17221695 Collection .__init__ (self , ** kwargs )
@@ -1743,11 +1716,10 @@ def set_paths(self):
17431716 @staticmethod
17441717 def convert_mesh_to_paths (tri ):
17451718 """
1746- Converts a given mesh into a sequence of
1747- :class:`matplotlib.path.Path` objects for easier rendering by
1748- backends that do not directly support meshes.
1719+ Converts a given mesh into a sequence of `~.Path` objects.
17491720
1750- This function is primarily of use to backend implementers.
1721+ This function is primarily of use to implementers of backends that do
1722+ not directly support meshes.
17511723 """
17521724 triangles = tri .get_masked_triangles ()
17531725 verts = np .stack ((tri .x [triangles ], tri .y [triangles ]), axis = - 1 )
@@ -1839,11 +1811,10 @@ def get_datalim(self, transData):
18391811 @staticmethod
18401812 def convert_mesh_to_paths (meshWidth , meshHeight , coordinates ):
18411813 """
1842- Converts a given mesh into a sequence of
1843- :class:`matplotlib.path.Path` objects for easier rendering by
1844- backends that do not directly support quadmeshes.
1814+ Converts a given mesh into a sequence of `~.Path` objects.
18451815
1846- This function is primarily of use to backend implementers.
1816+ This function is primarily of use to implementers of backends that do
1817+ not directly support quadmeshes.
18471818 """
18481819 if isinstance (coordinates , np .ma .MaskedArray ):
18491820 c = coordinates .data
@@ -1863,7 +1834,7 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
18631834 """
18641835 Converts a given mesh into a sequence of triangles, each point
18651836 with its own color. This is useful for experiments using
1866- `draw_qouraud_triangle `.
1837+ `draw_gouraud_triangle `.
18671838 """
18681839 if isinstance (coordinates , np .ma .MaskedArray ):
18691840 p = coordinates .data
0 commit comments