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" , "aa" ],
@@ -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,8 +224,7 @@ 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 :
227
+ if offsets .size :
232
228
xs = self .convert_xunits (offsets [:, 0 ])
233
229
ys = self .convert_yunits (offsets [:, 1 ])
234
230
offsets = np .column_stack ([xs , ys ])
@@ -336,7 +332,8 @@ def draw(self, renderer):
336
332
self .stale = False
337
333
338
334
def set_pickradius (self , pr ):
339
- """Set the pick radius used for containment tests.
335
+ """
336
+ Set the pick radius used for containment tests.
340
337
341
338
Parameters
342
339
----------
@@ -352,8 +349,8 @@ def contains(self, mouseevent):
352
349
"""
353
350
Test whether the mouse event occurred in the collection.
354
351
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.
357
354
"""
358
355
if callable (self ._contains ):
359
356
return self ._contains (self , mouseevent )
@@ -430,8 +427,7 @@ def get_hatch(self):
430
427
431
428
def set_offsets (self , offsets ):
432
429
"""
433
- Set the offsets for the collection. *offsets* can be a scalar
434
- or a sequence.
430
+ Set the offsets for the collection.
435
431
436
432
Parameters
437
433
----------
@@ -552,8 +548,7 @@ def set_linestyle(self, ls):
552
548
553
549
def set_capstyle (self , cs ):
554
550
"""
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).
557
552
558
553
Parameters
559
554
----------
@@ -570,8 +565,7 @@ def get_capstyle(self):
570
565
571
566
def set_joinstyle (self , js ):
572
567
"""
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).
575
569
576
570
Parameters
577
571
----------
@@ -588,28 +582,26 @@ def get_joinstyle(self):
588
582
589
583
@staticmethod
590
584
def _bcast_lwls (linewidths , dashes ):
591
- '''Internal helper function to broadcast + scale ls/lw
585
+ """
586
+ Internal helper function to broadcast + scale ls/lw
592
587
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.
598
592
599
593
Parameters
600
594
----------
601
595
linewidths : list
602
596
line widths of collection
603
-
604
597
dashes : list
605
598
dash specification (offset, (dash pattern tuple))
606
599
607
600
Returns
608
601
-------
609
602
linewidths, dashes : list
610
603
Will be the same length, dashes are scaled by paired linewidth
611
-
612
- '''
604
+ """
613
605
if mpl .rcParams ['_internal.classic_mode' ]:
614
606
return linewidths , dashes
615
607
# make sure they are the same length so we can zip them
@@ -723,26 +715,20 @@ def _set_edgecolor(self, c):
723
715
724
716
def set_edgecolor (self , c ):
725
717
"""
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.
734
719
735
720
Parameters
736
721
----------
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.
738
725
"""
739
726
self ._original_edgecolor = c
740
727
self ._set_edgecolor (c )
741
728
742
729
def set_alpha (self , alpha ):
743
730
"""
744
- Set the alpha tranparencies of the collection. *alpha* must be
745
- a float or *None*.
731
+ Set the alpha tranparencies of the collection.
746
732
747
733
Parameters
748
734
----------
@@ -765,10 +751,7 @@ def get_linestyle(self):
765
751
return self ._linestyles
766
752
767
753
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."""
772
755
if self ._A is None :
773
756
return
774
757
if self ._A .ndim > 1 :
@@ -861,7 +844,6 @@ def set_sizes(self, sizes, dpi=72.0):
861
844
sizes : ndarray or None
862
845
The size to set for each element of the collection. The
863
846
value is the 'area' of the element.
864
-
865
847
dpi : float
866
848
The dpi of the canvas. Defaults to 72.0.
867
849
"""
@@ -963,7 +945,7 @@ def set_verts(self, verts, closed=True):
963
945
set_paths = set_verts
964
946
965
947
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."""
967
949
if len (verts ) != len (codes ):
968
950
raise ValueError ("'codes' must be a 1D list or array "
969
951
"with the same length of 'verts'" )
@@ -1025,9 +1007,9 @@ def span_where(x, ymin, ymax, where, **kwargs):
1025
1007
1026
1008
class RegularPolyCollection (_CollectionWithSizes ):
1027
1009
"""Draw a collection of regular polygons with *numsides*."""
1028
- _path_generator = mpath .Path .unit_regular_polygon
1029
1010
1030
- _factor = CIRCLE_AREA_FACTOR
1011
+ _path_generator = mpath .Path .unit_regular_polygon
1012
+ _factor = np .pi ** (- 1 / 2 )
1031
1013
1032
1014
@docstring .dedent_interpd
1033
1015
def __init__ (self ,
@@ -1089,16 +1071,12 @@ def draw(self, renderer):
1089
1071
1090
1072
1091
1073
class StarPolygonCollection (RegularPolyCollection ):
1092
- """
1093
- Draw a collection of regular stars with *numsides* points."""
1094
-
1074
+ """Draw a collection of regular stars with *numsides* points."""
1095
1075
_path_generator = mpath .Path .unit_regular_star
1096
1076
1097
1077
1098
1078
class AsteriskPolygonCollection (RegularPolyCollection ):
1099
- """
1100
- Draw a collection of regular asterisks with *numsides* points."""
1101
-
1079
+ """Draw a collection of regular asterisks with *numsides* points."""
1102
1080
_path_generator = mpath .Path .unit_regular_asterisk
1103
1081
1104
1082
@@ -1295,13 +1273,13 @@ def get_color(self):
1295
1273
1296
1274
1297
1275
class EventCollection (LineCollection ):
1298
- '''
1276
+ """
1299
1277
A collection of discrete events.
1300
1278
1301
1279
The events are given by a 1-dimensional array, usually the position of
1302
1280
something along an axis, such as time or length. They do not have an
1303
1281
amplitude and are displayed as vertical or horizontal parallel bars.
1304
- '''
1282
+ """
1305
1283
1306
1284
_edge_default = True
1307
1285
@@ -1539,10 +1517,9 @@ def get_color(self):
1539
1517
1540
1518
1541
1519
class CircleCollection (_CollectionWithSizes ):
1542
- """
1543
- A collection of circles, drawn using splines.
1544
- """
1545
- _factor = CIRCLE_AREA_FACTOR
1520
+ """A collection of circles, drawn using splines."""
1521
+
1522
+ _factor = np .pi ** (- 1 / 2 )
1546
1523
1547
1524
@docstring .dedent_interpd
1548
1525
def __init__ (self , sizes , ** kwargs ):
@@ -1559,9 +1536,8 @@ def __init__(self, sizes, **kwargs):
1559
1536
1560
1537
1561
1538
class EllipseCollection (Collection ):
1562
- """
1563
- A collection of ellipses, drawn using splines.
1564
- """
1539
+ """A collection of ellipses, drawn using splines."""
1540
+
1565
1541
@docstring .dedent_interpd
1566
1542
def __init__ (self , widths , heights , angles , units = 'points' , ** kwargs ):
1567
1543
"""
@@ -1604,9 +1580,8 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
1604
1580
self ._paths = [mpath .Path .unit_circle ()]
1605
1581
1606
1582
def _set_transforms (self ):
1607
- """
1608
- Calculate transforms immediately before drawing.
1609
- """
1583
+ """Calculate transforms immediately before drawing."""
1584
+
1610
1585
ax = self .axes
1611
1586
fig = self .figure
1612
1587
@@ -1709,11 +1684,9 @@ def set_paths(self, patches):
1709
1684
1710
1685
class TriMesh (Collection ):
1711
1686
"""
1712
- Class for the efficient drawing of a triangular mesh using
1713
- Gouraud shading.
1687
+ Class for the efficient drawing of a triangular mesh using Gouraud shading.
1714
1688
1715
- A triangular mesh is a :class:`~matplotlib.tri.Triangulation`
1716
- object.
1689
+ A triangular mesh is a `~matplotlib.tri.Triangulation` object.
1717
1690
"""
1718
1691
def __init__ (self , triangulation , ** kwargs ):
1719
1692
Collection .__init__ (self , ** kwargs )
@@ -1740,11 +1713,10 @@ def set_paths(self):
1740
1713
@staticmethod
1741
1714
def convert_mesh_to_paths (tri ):
1742
1715
"""
1743
- Converts a given mesh into a sequence of
1744
- :class:`matplotlib.path.Path` objects for easier rendering by
1745
- backends that do not directly support meshes.
1716
+ Converts a given mesh into a sequence of `~.Path` objects.
1746
1717
1747
- This function is primarily of use to backend implementers.
1718
+ This function is primarily of use to implementers of backends that do
1719
+ not directly support meshes.
1748
1720
"""
1749
1721
triangles = tri .get_masked_triangles ()
1750
1722
verts = np .stack ((tri .x [triangles ], tri .y [triangles ]), axis = - 1 )
@@ -1836,11 +1808,10 @@ def get_datalim(self, transData):
1836
1808
@staticmethod
1837
1809
def convert_mesh_to_paths (meshWidth , meshHeight , coordinates ):
1838
1810
"""
1839
- Converts a given mesh into a sequence of
1840
- :class:`matplotlib.path.Path` objects for easier rendering by
1841
- backends that do not directly support quadmeshes.
1811
+ Converts a given mesh into a sequence of `~.Path` objects.
1842
1812
1843
- This function is primarily of use to backend implementers.
1813
+ This function is primarily of use to implementers of backends that do
1814
+ not directly support quadmeshes.
1844
1815
"""
1845
1816
if isinstance (coordinates , np .ma .MaskedArray ):
1846
1817
c = coordinates .data
@@ -1860,7 +1831,7 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
1860
1831
"""
1861
1832
Converts a given mesh into a sequence of triangles, each point
1862
1833
with its own color. This is useful for experiments using
1863
- `draw_qouraud_triangle `.
1834
+ `draw_gouraud_triangle `.
1864
1835
"""
1865
1836
if isinstance (coordinates , np .ma .MaskedArray ):
1866
1837
p = coordinates .data
0 commit comments