10000 Merge pull request #12852 from anntzer/collectiondocs · matplotlib/matplotlib@64f0309 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64f0309

Browse files
authored
Merge pull request #12852 from anntzer/collectiondocs
Cleanup collections docs.
2 parents 8272e7b + 7d83aa0 commit 64f0309

File tree

2 files changed

+50
-75
lines changed

2 files changed

+50
-75
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Removals
2+
````````
3+
4+
The ``collections.CIRCLE_AREA_FACTOR`` constant has been removed.

lib/matplotlib/collections.py

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from . 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", "aa"],
@@ -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

10261008
class 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

10911073
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."""
10951075
_path_generator = mpath.Path.unit_regular_star
10961076

10971077

10981078
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."""
11021080
_path_generator = mpath.Path.unit_regular_asterisk
11031081

11041082

@@ -1295,13 +1273,13 @@ def get_color(self):
12951273

12961274

12971275
class 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

@@ -1539,10 +1517,9 @@ def get_color(self):
15391517

15401518

15411519
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)
15461523

15471524
@docstring.dedent_interpd
15481525
def __init__(self, sizes, **kwargs):
@@ -1559,9 +1536,8 @@ def __init__(self, sizes, **kwargs):
15591536

15601537

15611538
class EllipseCollection(Collection):
1562-
"""
1563-
A collection of ellipses, drawn using splines.
1564-
"""
1539+
"""A collection of ellipses, drawn using splines."""
1540+
15651541
@docstring.dedent_interpd
15661542
def __init__(self, widths, heights, angles, units='points', **kwargs):
15671543
"""
@@ -1604,9 +1580,8 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
16041580
self._paths = [mpath.Path.unit_circle()]
16051581

16061582
def _set_transforms(self):
1607-
"""
1608-
Calculate transforms immediately before drawing.
1609-
"""
1583+
"""Calculate transforms immediately before drawing."""
1584+
16101585
ax = self.axes
16111586
fig = self.figure
16121587

@@ -1709,11 +1684,9 @@ def set_paths(self, patches):
17091684

17101685
class TriMesh(Collection):
17111686
"""
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.
17141688
1715-
A triangular mesh is a :class:`~matplotlib.tri.Triangulation`
1716-
object.
1689+
A triangular mesh is a `~matplotlib.tri.Triangulation` object.
17171690
"""
17181691
def __init__(self, triangulation, **kwargs):
17191692
Collection.__init__(self, **kwargs)
@@ -1740,11 +1713,10 @@ def set_paths(self):
17401713
@staticmethod
17411714
def convert_mesh_to_paths(tri):
17421715
"""
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.
17461717
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.
17481720
"""
17491721
triangles = tri.get_masked_triangles()
17501722
verts = np.stack((tri.x[triangles], tri.y[triangles]), axis=-1)
@@ -1836,11 +1808,10 @@ def get_datalim(self, transData):
18361808
@staticmethod
18371809
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
18381810
"""
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.
18421812
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.
18441815
"""
18451816
if isinstance(coordinates, np.ma.MaskedArray):
18461817
c = coordinates.data
@@ -1860,7 +1831,7 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
18601831
"""
18611832
Converts a given mesh into a sequence of triangles, each point
18621833
with its own color. This is useful for experiments using
1863-
`draw_qouraud_triangle`.
1834+
`draw_gouraud_triangle`.
18641835
"""
18651836
if isinstance(coordinates, np.ma.MaskedArray):
18661837
p = coordinates.data

0 commit comments

Comments
 (0)
0