27
27
"linewidth" : ["linewidths" , "lw" ],
28
28
})
29
29
class Collection (artist .Artist , cm .ScalarMappable ):
30
- """
30
+ r """
31
31
Base class for Collections. Must be subclassed to be usable.
32
32
33
- A Collection represents a sequence of `~.patches.Patch` objects that the
34
- library believes would be more efficient to draw together than
35
- individually. For example, when a single path is being drawn repeatedly at
36
- different offsets, the renderer can typically execute a `draw_marker` call
37
- much more efficiently than a series of repeated calls to `draw_path` with
38
- the offsets put in one-by-one.
33
+ A Collection represents a sequence of `~.patches.Patch`\s that can be drawn
34
+ more efficiently together than individually. For example, when a single
35
+ path is being drawn repeatedly at different offsets, the renderer can
36
+ typically execute a ``draw_marker()`` call much more efficiently than a
37
+ series of repeated calls to ``draw_path()`` with the offsets put in
38
+ one-by-one.
39
+
40
+ Most properties of a collection can be configured per-element. Therefore,
41
+ Collections have "plural" versions of many of the properties of a
42
+ `~.patches.Patch` (e.g. `.Collection.get_paths` instead of
43
+ `~.patches.Patch.get_path`). Exceptions are the *zorder*, *hatch*,
44
+ *pickradius*, *capstyle* and *joinstyle* properties, which can only be set
45
+ globally for the whole collection.
39
46
40
- All properties in a collection can be either sequences or scalars; if
41
- scalars, they will be converted to sequences. The property of the ith
42
- element of the collection is::
47
+ Besides these exceptions, all properties can be specified as single values
48
+ (applying to all elements) or sequences of values . The property of the
49
+ ``i``th element of the collection is::
43
50
44
- prop[i % len(props )]
51
+ prop[i % len(prop )]
45
52
46
- Because of this, Collections have "plural" versions of many of the
47
- properties of a `~.patches.Patch` (e.g. `Collection.get_paths` instead of
48
- `~.patches.Patch.get_path`). Exceptions are the *hatch*, *pickradius*,
49
- *capstyle* and *joinstyle* properties, these can only be set globally for
50
- the whole collection.
51
53
52
54
Each Collection can optionally be used as its own `~.cm.ScalarMappable` by
53
55
passing the *norm* and *cmap* parameters to its constructor. If the
54
56
Collection's `~.cm.ScalarMappable` matrix ``_A`` has been set (via a call
55
- to `Collection.set_array`), then at draw time this internal scalar mappable
56
- will be used to set the ``facecolors`` and ``edgecolors``, ignoring those
57
- that were manually passed in.
57
+ to `. Collection.set_array`), then at draw time this internal scalar
58
+ mappable will be used to set the ``facecolors`` and ``edgecolors``,
59
+ ignoring those that were manually passed in.
58
60
"""
59
61
_offsets = np .zeros ((0 , 2 ))
60
62
_transOffset = transforms .IdentityTransform ()
@@ -91,13 +93,19 @@ def __init__(self,
91
93
** kwargs
92
94
):
93
95
"""
96
+ For all "plural" parameters, the type listed is the expected type when
97
+ passing a single value to be used for the whole collection. For any of
98
+ these inputs, a Sequence of the specified type is also allowed.
99
+
94
100
Parameters
95
101
----------
96
- edgecolors : default: :rc:`patch.edgecolor`
97
- Edge color for each patch making up the collection.
98
- facecolors : default: :rc:`patch.facecolor`
102
+ edgecolors : color, default: :rc:`patch.edgecolor`
103
+ Edge color for each patch making up the collection. The special
104
+ value 'face' can be passed to make the edgecolor match the
105
+ facecolor.
106
+ facecolors : color, default: :rc:`patch.facecolor`
99
107
Face color for each patch making up the collection.
100
- linewidths : default: :rc:`patch.linewidth`
108
+ linewidths : float, default: :rc:`patch.linewidth`
101
109
Line width for each patch making up the collection.
102
110
linestyles : str or tuple, default: 'solid'
103
111
Valid strings are ['solid', 'dashed', 'dashdot', 'dotted', '-',
@@ -108,14 +116,14 @@ def __init__(self,
108
116
where *onoffseq* is an even length tuple of on and off ink lengths
109
117
in points. For examples, see
110
118
:doc:`/gallery/lines_bars_and_markers/linestyles`.
111
- capstyle : default: :rc:`patch.capstyle`
119
+ capstyle : str, default: :rc:`patch.capstyle`
112
120
Style to use for capping lines for all paths in the collection.
113
- joinstyle : default: :rc:`patch.joinstyle`
121
+ joinstyle : str, default: :rc:`patch.joinstyle`
114
122
Style to use for joining lines for all paths in the collection.
115
- antialiaseds : default: :rc:`patch.antialiased`
123
+ antialiaseds : bool, default: :rc:`patch.antialiased`
116
124
Whether each pach in the collection should be drawn with
117
125
antialiasing.
118
- offsets : Tuple[ float, float] , default: (0, 0)
126
+ offsets : ( float, float) , default: (0, 0)
119
127
A vector by which to translate each patch after rendering (default
120
128
is no translation). The translation is performed in screen (pixel)
121
129
coordinates (i.e. after the Artist's transform is applied).
@@ -126,25 +134,25 @@ def __init__(self,
126
134
If set to 'data' (deprecated), *offsets* will be treated as if it
127
135
is in data coordinates instead of in screen coordinates.
128
136
norm : `~.colors.Normalize`, optional, default: None
129
- Forwarded to `~.cm.ScalarMappable.__init__ `. The default of
137
+ Forwarded to `~.cm.ScalarMappable`. The default of
130
138
``None`` means that the first draw call will set ``vmin`` and
131
139
``vmax`` using the minimum and maximum values of the data.
132
140
cmap : `~.colors.Colormap`, optional, default: None
133
- Forwarded to `~.cm.ScalarMappable.__init__ `. The default of
141
+ Forwarded to `~.cm.ScalarMappable`. The default of
134
142
``None`` will result in :rc:`image.cmap` being used.
135
- hatch : Optional[ str] , default: None
143
+ hatch : str, optional , default: None
136
144
Hatching pattern to use in filled paths, if any. Valid strings are
137
145
['/', '\\ ', '|', '-', '+', 'x', 'o', 'O', '.', '*']. See
138
146
:doc:`/gallery/shapes_and_collections/hatch_demo` for the meaning
139
147
of each hatch type.
140
- pickradius : float, default: 5
141
- If ``pickradius <= 0``, then `Collection.contains` will return
148
+ pickradius : float, default: 5.0
149
+ If ``pickradius <= 0``, then `. Collection.contains` will return
142
150
``True`` whenever the test point is inside of one of the polygons
143
151
formed by the control points of a Path in the Collection. On the
144
152
other hand, if it is greater than 0, then we instead check if the
145
153
test point is contained in a stroke of width ``2*pickradius``
146
154
following any of the Paths in the Collection.
147
- urls : str or Sequence[str] , default: None
155
+ urls : str, default: None
148
156
A URL for each patch to link to once drawn. Currently only works
149
157
for the SVG backend. See :doc:`/gallery/misc/hyperlinks_sgskip` for
150
158
examples.
@@ -223,24 +231,21 @@ def get_offset_transform(self):
223
231
return t
224
232
225
233
def get_datalim (self , transData ):
226
- """
227
- Get the automatic datalim of the collection.
228
-
229
- This operation depends on the transforms for the data in the
230
- collection and whether the collection has offsets.
231
-
232
- 1. offsets = None, transform child of transData: use the paths for
233
- the automatic limits (i.e. for LineCollection in streamline).
234
- 2. offsets != None: offset_transform is child of transData:
235
-
236
- a. transform is child of transData: use the path + offset for
237
- limits (i.e for bar).
238
- b. transform is not a child of transData: just use the offsets
239
- for the limits (i.e. for scatter)
240
-
241
- 3. otherwise return a null Bbox.
242
-
243
- """
234
+ # Calculate the data limits and return them as a `.Bbox`.
235
+ #
236
+ # This operation depends on the transforms for the data in the
237
+ # collection and whether the collection has offsets:
238
+ #
239
+ # 1. offsets = None, transform child of transData: use the paths for
240
+ # the automatic limits (i.e. for LineCollection in streamline).
241
+ # 2. offsets != None: offset_transform is child of transData:
242
+ #
243
+ # a. transform is child of transData: use the path + offset for
244
+ # limits (i.e for bar).
245
+ # b. transform is not a child of transData: just use the offsets
246
+ # for the limits (i.e. for scatter)
247
+ #
248
+ # 3. otherwise return a null Bbox.
244
249
245
250
transform = self .get_transform ()
246
251
transOffset = self .get_offset_transform ()
@@ -439,10 +444,11 @@ def contains(self, mouseevent):
439
444
if not self .get_visible ():
440
445
return False , {}
441
446
442
- if isinstance (self ._picker , Number ) and self ._picker is not True :
443
- pickradius = float (self ._picker ) # Artist._picker not just a bool
444
- else :
445
- pickradius = self ._pickradius
447
+ pickradius = (
448
+ float (self ._picker )
449
+ if isinstance (self ._picker , Number ) and
450
+ self ._picker is not True # the bool, not just nonzero or 1
451
+ else self ._pickradius )
446
452
447
453
if self .axes :
448
454
self .axes ._unstale_viewLim ()
@@ -466,21 +472,22 @@ def set_urls(self, urls):
466
472
"""
467
473
Parameters
468
474
----------
469
- urls : List[ str] or None
475
+ urls : list of str or None
470
476
471
477
Notes
472
478
-----
473
- Currently only works for the SVG backend.
479
+ URLs are currently only implemented by the SVG backend. They are
480
+ ignored by all other backends.
474
481
"""
475
482
self ._urls = urls if urls is not None else [None ]
476
483
self .stale = True
477
484
478
485
def get_urls (self ):
479
486
"""
480
- Returns
481
- -------
482
- The URL that each patch should link to once drawn . See
483
- :doc:`/gallery/misc/hyperlinks_sgskip` for a examples .
487
+ Return a list of URLs, one for each element of the collection.
488
+
489
+ The list contains *None* for elements without a URL . See
490
+ :doc:`/gallery/misc/hyperlinks_sgskip` for an example .
484
491
"""
485
492
return self ._urls
486
493
@@ -925,21 +932,21 @@ def draw(self, renderer):
925
932
926
933
class PathCollection (_CollectionWithSizes ):
927
934
"""
928
- The most basic `Collection` subclass, created e.g. by `~.Axes.scatter`.
935
+ The most basic `. Collection` subclass, created e.g. by `~.Axes.scatter`.
929
936
"""
930
937
931
938
def __init__ (self , paths , sizes = None , ** kwargs ):
932
939
"""
933
940
Parameters
934
941
----------
935
- paths : Sequence[ matplotlib.path.Path]
936
- The paths that will make up the `Collection`.
937
- sizes : Sequence[ float]
938
- Scalar by which to scale each drawn `~.path.Path`. One unit squared
939
- in the Path's data space is scaled to be ``sizes**2`` points when
940
- rendered.
942
+ paths : list of matplotlib.path.Path
943
+ The paths that will make up the `. Collection`.
944
+ sizes : array-like of float
945
+ The factor by which to scale each drawn `~.path.Path`. One unit
946
+ squared in the Path's data space is scaled to be ``sizes**2``
947
+ points when rendered.
941
948
**kwargs
942
- Forwarded to `Collection`.
949
+ Forwarded to `. Collection`.
943
950
"""
944
951
945
952
super ().__init__ (** kwargs )
@@ -959,17 +966,17 @@ def legend_elements(self, prop="colors", num="auto",
959
966
"""
960
967
Create legend handles and labels for a PathCollection.
961
968
962
- Each legend handle is just a `.Line2D` representing the Path that was
963
- drawn, and each label is just a string what each Path represents.
969
+ Each legend handle is a `.Line2D` representing the Path that was drawn,
970
+ and each label is a string what each Path represents.
964
971
965
972
This is useful for obtaining a legend for a `~.Axes.scatter` plot;
966
973
e.g.::
967
974
968
975
scatter = plt.scatter([1, 2, 3], [4, 5, 6], c=[7, 2, 3])
969
976
plt.legend(*scatter.legend_elements())
970
977
971
- would create three legend elements, one for each color with the
972
- numerical values passed to *c* as the labels.
978
+ creates three legend elements, one for each color with the numerical
979
+ values passed to *c* as the labels.
973
980
974
981
Also see the :ref:`automatedlegendcreation` example.
975
982
@@ -1109,7 +1116,7 @@ def __init__(self, verts, sizes=None, closed=True, **kwargs):
1109
1116
Whether the polygon should be closed by adding a CLOSEPOLY
1110
1117
connection at the end.
1111
1118
**kwargs
1112
- Forwarded to `Collection`.
1119
+ Forwarded to `. Collection`.
1113
1120
"""
1114
1121
Collection .__init__ (self , ** kwargs )
1115
1122
self .set_sizes (sizes )
@@ -1192,7 +1199,7 @@ def __init__(self, xranges, yrange, **kwargs):
1192
1199
yrange : (float, float)
1193
1200
The (lower-edge, height) common to all bars.
1194
1201
**kwargs
1195
- Forwarded to `Collection`.
1202
+ Forwarded to `. Collection`.
1196
1203
"""
1197
1204
ymin , ywidth = yrange
1198
1205
ymax = ymin + ywidth
@@ -1206,7 +1213,7 @@ def __init__(self, xranges, yrange, **kwargs):
1206
1213
@classmethod
1207
1214
def span_where (cls , x , ymin , ymax , where , ** kwargs ):
1208
1215
"""
1209
- Return a `BrokenBarHCollection` that plots horizontal bars from
1216
+ Return a `. BrokenBarHCollection` that plots horizontal bars from
1210
1217
over the regions in *x* where *where* is True. The bars range
1211
1218
on the y-axis from *ymin* to *ymax*
1212
1219
@@ -1242,7 +1249,7 @@ def __init__(self,
1242
1249
sizes : tuple of float
1243
1250
The area of the circle circumscribing the polygon in points^2.
1244
1251
**kwargs
1245
- Forwarded to `Collection`.
1252
+ Forwarded to `. Collection`.
1246
1253
1247
1254
Examples
1248
1255
--------
@@ -1296,7 +1303,7 @@ class AsteriskPolygonCollection(RegularPolyCollection):
1296
1303
1297
1304
class LineCollection (Collection ):
1298
1305
"""
1299
- A collection of 2D lines, where each line can be many segments long .
1306
+ Collection of 2D lines. Each line may have an arbitrary number of segments .
1300
1307
1301
1308
Relevant parameters default to their ``'lines'`` values in
1302
1309
`~.matplotlib.rcParams` instead of their ``'patch'`` values.
@@ -1319,6 +1326,13 @@ def __init__(self, segments, # Can be None.
1319
1326
** kwargs
1320
1327
):
1321
1328
"""
1329
+ Except for *segments*, the type listed below is the expected type when
1330
+ passing a single value to be used for the whole collection. A Sequence
1331
+ of the specified type is also allowed, in which case the property for
1332
+ the ``i``th element of the collection will be::
1333
+
1334
+ prop[i % len(prop)]
1335
+
1322
1336
Parameters
1323
1337
----------
1324
1338
segments
@@ -1328,9 +1342,9 @@ def __init__(self, segments, # Can be None.
1328
1342
1329
1343
or the equivalent numpy array with two columns. Each line
1330
1344
can have a different number of segments.
1331
- linewidths : default: :rc:`lines.linewidth`
1345
+ linewidths : float, default: :rc:`lines.linewidth`
1332
1346
The width of each line in points.
1333
- colors : default: :rc:`lines.color`
1347
+ colors : color, default: :rc:`lines.color`
1334
1348
A sequence of RGBA tuples (e.g., arbitrary color strings, etc, not
1335
1349
allowed).
1336
1350
antialiaseds : default: :rc:`lines.antialiased`
@@ -1343,10 +1357,11 @@ def __init__(self, segments, # Can be None.
1343
1357
"filled in" as if there was an implicit line segment joining the
1344
1358
last and first points of that line back around to each other. In
1345
1359
order to manually specify what should count as the "interior" of
1346
- each line, please use `PathCollection` instead, where the "interior"
1347
- can be specified by appropriate usage of `~.path.Path.CLOSEPOLY`.
1360
+ each line, please use `.PathCollection` instead, where the
1361
+ "interior" can be specified by appropriate usage of
1362
+ `~.path.Path.CLOSEPOLY`.
1348
1363
**kwargs
1349
- Forwareded to `Collection`.
1364
+ Forwareded to `. Collection`.
1350
1365
"""
1351
1366
if colors is None :
1352
1367
colors = mpl .rcParams ['lines.color' ]
@@ -1492,7 +1507,7 @@ def __init__(self,
1492
1507
antialiased : bool, default: :rc:`lines.antialiased`
1493
1508
Whether to use antialiasing for drawing the lines.
1494
1509
**kwargs
1495
- Forwarded to :class:`~matplotlib.collections .LineCollection`.
1510
+ Forwarded to ` .LineCollection`.
1496
1511
1497
1512
Examples
1498
1513
--------
@@ -1650,10 +1665,10 @@ def __init__(self, sizes, **kwargs):
1650
1665
"""
1651
1666
Parameters
1652
1667
----------
1653
- sizes : float or Sequence[float]
1668
+ sizes : float or array-like
1654
1669
Gives the area of each circle in points^2.
1655
1670
**kwargs
1656
- Forwarded to `Collection`.
1671
+ Forwarded to `. Collection`.
1657
1672
"""
1658
1673
Collection .__init__ (self , ** kwargs )
1659
1674
self .set_sizes (sizes )
@@ -1687,7 +1702,7 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
1687
1702
it behaves the same as the `~matplotlib.patches.Ellipse` with
1688
1703
``axes.transData`` as its transform.
1689
1704
**kwargs
1690
- Forwarded to :class: `Collection`.
1705
+ Forwarded to `Collection`.
1691
1706
"""
1692
1707
Collection .__init__ (self , ** kwargs )
1693
1708
self ._widths = 0.5 * np .asarray (widths ).ravel ()
0 commit comments