17
17
from . import (_path , artist , cbook , cm , colors as mcolors , docstring ,
18
18
lines as mlines , path as mpath , transforms )
19
19
20
- CIRCLE_AREA_FACTOR = 1.0 / np .sqrt (np .pi )
21
-
22
20
23
21
@cbook ._define_aliases ({
24
22
"antialiased" : ["antialiaseds" ],
@@ -58,7 +56,6 @@ class Collection(artist.Artist, cm.ScalarMappable):
58
56
* *hatch*: None
59
57
* *zorder*: 1
60
58
61
-
62
59
*offsets* and *transOffset* are used to translate the patch after
63
60
rendering (default no offsets). If offset_position is 'screen'
64
61
(default) the offset is applied after the master transform has
@@ -207,12 +204,12 @@ def get_datalim(self, transData):
207
204
return result
208
205
209
206
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
211
208
# cases other than scatter plot legend
212
209
return self .get_datalim (transforms .IdentityTransform ())
213
210
214
211
def _prepare_points (self ):
215
- """Point prep for drawing and hit testing"""
212
+ # Helper for drawing and hit testing.
216
213
217
214
transform = self .get_transform ()
218
215
transOffset = self .get_offset_transform ()
@@ -227,11 +224,9 @@ def _prepare_points(self):
227
224
xs = self .convert_xunits (xs )
228
225
ys = self .convert_yunits (ys )
229
226
paths .append (mpath .Path (np .column_stack ([xs , ys ]), path .codes ))
230
-
231
- if offsets .size > 0 :
232
- xs = self .convert_xunits (offsets [:, 0 ])
233
- ys = self .convert_yunits (offsets [:, 1 ])
234
- offsets = np .column_stack ([xs , ys ])
227
+ xs = self .convert_xunits (offsets [:, 0 ])
228
+ ys = self .convert_yunits (offsets [:, 1 ])
229
+ offsets = np .column_stack ([xs , ys ])
235
230
236
231
if not transform .is_affine :
237
232
paths = [transform .transform_path_non_affine (path )
@@ -336,7 +331,8 @@ def draw(self, renderer):
336
331
self .stale = False
337
332
338
333
def set_pickradius (self , pr ):
339
- """Set the pick radius used for containment tests.
334
+ """
335
+ Set the pick radius used for containment tests.
340
336
341
337
Parameters
342
338
----------
@@ -352,8 +348,8 @@ def contains(self, mouseevent):
352
348
"""
353
349
Test whether the mouse event occurred in the collection.
354
350
355
- Returns True | False, `` dict(ind=itemlist)``, where every
356
- item in itemlist contains the event.
351
+ Returns ``bool, dict(ind=itemlist)``, where every item in itemlist
352
+ contains the event.
357
353
"""
358
354
if callable (self ._contains ):
359
355
return self ._contains (self , mouseevent )
@@ -430,8 +426,7 @@ def get_hatch(self):
430
426
431
427
def set_offsets (self , offsets ):
432
428
"""
433
- Set the offsets for the collection. *offsets* can be a scalar
434
- or a sequence.
429
+ Set the offsets for the collection.
435
430
436
431
Parameters
437
432
----------
@@ -552,8 +547,7 @@ def set_linestyle(self, ls):
552
547
553
548
def set_capstyle (self , cs ):
554
549
"""
555
- Set the capstyle for the collection. The capstyle can
556
- only be set globally for all elements in the collection
550
+ Set the capstyle for the collection (for all its elements).
557
551
558
552
Parameters
559
553
----------
@@ -570,8 +564,7 @@ def get_capstyle(self):
570
564
571
565
def set_joinstyle (self , js ):
572
566
"""
573
- Set the joinstyle for the collection. The joinstyle can only be
574
- set globally for all elements in the collection.
567
+ Set the joinstyle for the collection (for all its elements).
575
568
576
569
Parameters
577
570
----------
@@ -588,28 +581,26 @@ def get_joinstyle(self):
588
581
589
582
@staticmethod
590
583
def _bcast_lwls (linewidths , dashes ):
591
- '''Internal helper function to broadcast + scale ls/lw
584
+ """
585
+ Internal helper function to broadcast + scale ls/lw
592
586
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.
587
+ In the collection drawing code, the linewidth and linestyle are cycled
588
+ through as circular buffers (via ``v[i % len(v)]``). Thus, if we are
589
+ going to scale the dash pattern at set time (not draw time) we need to
590
+ do the broadcasting now and expand both lists to be the same length.
598
591
599
592
Parameters
600
593
----------
601
594
linewidths : list
602
595
line widths of collection
603
-
604
596
dashes : list
605
597
dash specification (offset, (dash pattern tuple))
606
598
607
599
Returns
608
600
-------
609
601
linewidths, dashes : list
610
602
Will be the same length, dashes are scaled by paired linewidth
611
-
612
- '''
603
+ """
613
604
if mpl .rcParams ['_internal.classic_mode' ]:
614
605
return linewidths , dashes
615
606
# make sure they are the same length so we can zip them
@@ -723,26 +714,20 @@ def _set_edgecolor(self, c):
723
714
724
715
def set_edgecolor (self , c ):
725
716
"""
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.
717
+ Set the edgecolor(s) of the collection.
734
718
735
719
Parameters
736
720
----------
737
- c : color or sequence of colors
721
+ c : color or sequence of colors or 'face'
722
+ The collection edgecolor(s). If a sequence, the patches cycle
723
+ through it. If 'face', match the facecolor.
738
724
"""
739
725
self ._original_edgecolor = c
740
726
self ._set_edgecolor (c )
741
727
742
728
def set_alpha (self , alpha ):
743
729
"""
744
- Set the alpha tranparencies of the collection. *alpha* must be
745
- a float or *None*.
730
+ Set the alpha tranparencies of the collection.
746
731
747
732
Parameters
748
733
----------
@@ -765,10 +750,7 @@ def get_linestyle(self):
765
750
return self ._linestyles
766
751
767
752
def update_scalarmappable (self ):
768
- """
769
- If the scalar mappable array is not none, update colors
770
- from scalar data
771
- """
753
+ """Update colors from the scalar mappable array, if it is not None."""
772
754
if self ._A is None :
773
755
return
774
756
if self ._A .ndim > 1 :
@@ -861,7 +843,6 @@ def set_sizes(self, sizes, dpi=72.0):
861
843
sizes : ndarray or None
862
844
The size to set for each element of the collection. The
863
845
value is the 'area' of the element.
864
-
865
846
dpi : float
866
847
The dpi of the canvas. Defaults to 72.0.
867
848
"""
@@ -963,7 +944,7 @@ def set_verts(self, verts, closed=True):
963
944
set_paths = set_verts
964
945
965
946
def set_verts_and_codes (self , verts , codes ):
966
- ''' This allows one to initialize vertices with path codes.'''
947
+ """ This allows one to initialize vertices with path codes."""
967
948
if len (verts ) != len (codes ):
968
949
raise ValueError ("'codes' must be a 1D list or array "
969
950
"with the same length of 'verts'" )
@@ -1025,9 +1006,9 @@ def span_where(x, ymin, ymax, where, **kwargs):
1025
1006
1026
1007
class RegularPolyCollection (_CollectionWithSizes ):
1027
1008
"""Draw a collection of regular polygons with *numsides*."""
1028
- _path_generator = mpath .Path .unit_regular_polygon
1029
1009
1030
- _factor = CIRCLE_AREA_FACTOR
1010
+ _path_generator = mpath .Path .unit_regular_polygon
1011
+ _factor = np .pi ** (- 1 / 2 )
1031
1012
1032
1013
@docstring .dedent_interpd
1033
1014
def __init__ (self ,
@@ -1089,16 +1070,12 @@ def draw(self, renderer):
1089
1070
1090
1071
1091
1072
class StarPolygonCollection (RegularPolyCollection ):
1092
- """
1093
- Draw a collection of regular stars with *numsides* points."""
1094
-
1073
+ """Draw a collection of regular stars with *numsides* points."""
1095
1074
_path_generator = mpath .Path .unit_regular_star
1096
1075
1097
1076
1098
1077
class AsteriskPolygonCollection (RegularPolyCollection ):
1099
- """
1100
- Draw a collection of regular asterisks with *numsides* points."""
1101
-
1078
+ """Draw a collection of regular asterisks with *numsides* points."""
1102
1079
_path_generator = mpath .Path .unit_regular_asterisk
1103
1080
1104
1081
@@ -1295,13 +1272,13 @@ def get_color(self):
1295
1272
1296
1273
1297
1274
class EventCollection (LineCollection ):
1298
- '''
1275
+ """
1299
1276
A collection of discrete events.
1300
1277
1301
1278
The events are given by a 1-dimensional array, usually the position of
1302
1279
something along an axis, such as time or length. They do not have an
1303
1280
amplitude and are displayed as vertical or horizontal parallel bars.
1304
- '''
1281
+ """
1305
1282
1306
1283
_edge_default = True
1307
1284
@@ -1542,10 +1519,9 @@ def get_color(self):
1542
1519
1543
1520
1544
1521
class CircleCollection (_CollectionWithSizes ):
1545
- """
1546
- A collection of circles, drawn using splines.
1547
- """
1548
- _factor = CIRCLE_AREA_FACTOR
1522
+ """A collection of circles, drawn using splines."""
1523
+
1524
+ _factor = np .pi ** (- 1 / 2 )
1549
1525
1550
1526
@docstring .dedent_interpd
1551
1527
def __init__ (self , sizes , ** kwargs ):
@@ -1562,9 +1538,8 @@ def __init__(self, sizes, **kwargs):
1562
1538
1563
1539
1564
1540
class EllipseCollection (Collection ):
1565
- """
1566
- A collection of ellipses, drawn using splines.
1567
- """
1541
+ """A collection of ellipses, drawn using splines."""
1542
+
1568
1543
@docstring .dedent_interpd
1569
1544
def __init__ (self , widths , heights , angles , units = 'points' , ** kwargs ):
1570
1545
"""
@@ -1607,9 +1582,8 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
1607
1582
self ._paths = [mpath .Path .unit_circle ()]
1608
1583
1609
1584
def _set_transforms (self ):
1610
- """
1611
- Calculate transforms immediately before drawing.
1612
- """
1585
+ """Calculate transforms immediately before drawing."""
1586
+
1613
1587
ax = self .axes
1614
1588
fig = self .figure
1615
1589
@@ -1712,11 +1686,9 @@ def set_paths(self, patches):
1712
1686
1713
1687
class TriMesh (Collection ):
1714
1688
"""
1715
- Class for the efficient drawing of a triangular mesh using
1716
- Gouraud shading.
1689
+ Class for the efficient drawing of a triangular mesh using Gouraud shading.
1717
1690
1718
- A triangular mesh is a :class:`~matplotlib.tri.Triangulation`
1719
- object.
1691
+ A triangular mesh is a `~matplotlib.tri.Triangulation` object.
1720
1692
"""
1721
1693
def __init__ (self , triangulation , ** kwargs ):
1722
1694
Collection .__init__ (self , ** kwargs )
@@ -1743,11 +1715,10 @@ def set_paths(self):
1743
1715
@staticmethod
1744
1716
def convert_mesh_to_paths (tri ):
1745
1717
"""
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.
1718
+ Converts a given mesh into a sequence of `~.Path` objects.
1749
1719
1750
- This function is primarily of use to backend implementers.
1720
+ This function is primarily of use to implementers of backends that do
1721
+ not directly support meshes.
1751
1722
"""
1752
1723
triangles = tri .get_masked_triangles ()
1753
1724
verts = np .stack ((tri .x [triangles ], tri .y [triangles ]), axis = - 1 )
@@ -1839,11 +1810,10 @@ def get_datalim(self, transData):
1839
1810
@staticmethod
1840
1811
def convert_mesh_to_paths (meshWidth , meshHeight , coordinates ):
1841
1812
"""
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.
1813
+ Converts a given mesh into a sequence of `~.Path` objects.
1845
1814
1846
- This function is primarily of use to backend implementers.
1815
+ This function is primarily of use to implementers of backends that do
1816
+ not directly support quadmeshes.
1847
1817
"""
1848
1818
if isinstance (coordinates , np .ma .MaskedArray ):
1849
1819
c = coordinates .data
@@ -1863,7 +1833,7 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
1863
1833
"""
1864
1834
Converts a given mesh into a sequence of triangles, each point
1865
1835
with its own color. This is useful for experiments using
1866
- `draw_qouraud_triangle `.
1836
+ `draw_gouraud_triangle `.
1867
1837
"""
1868
1838
if isinstance (coordinates , np .ma .MaskedArray ):
1869
1839
p = coordinates .data
0 commit comments