8000 Cleanup collections docs. · matplotlib/matplotlib@946e44c · GitHub
[go: up one dir, main page]

Skip to content

Commit 946e44c

Browse files
committed
Cleanup collections docs.
1 parent fe8468a commit 946e44c

File tree

2 files changed

+52
-78
lines changed

2 files changed

+52
-78
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: 48 additions & 78 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"],
@@ -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,11 +224,9 @@ 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:
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])
235230

236231
if not transform.is_affine:
237232
paths = [transform.transform_path_non_affine(path)
@@ -336,7 +331,8 @@ def draw(self, renderer):
336331
self.stale = False
337332

338333
def set_pickradius(self, pr):
339-
"""Set the pick radius used for containment tests.
334+
"""
335+
Set the pick radius used for containment tests.
340336
341337
Parameters
342338
----------
@@ -352,8 +348,8 @@ def contains(self, mouseevent):
352348
"""
353349
Test whether the mouse event occurred in the collection.
354350
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.
357353
"""
358354
if callable(self._contains):
359355
return self._contains(self, mouseevent)
@@ -430,8 +426,7 @@ def get_hatch(self):
430426

431427
def set_offsets(self, offsets):
432428
"""
433-
Set the offsets for the collection. *offsets* can be a scalar
434-
or a sequence.
429+
Set the offsets for the collection.
435430
436431
Parameters
437432
----------
@@ -552,8 +547,7 @@ def set_linestyle(self, ls):
552547

553548
def set_capstyle(self, cs):
554549
"""
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).
557551
558552
Parameters
559553
----------
@@ -570,8 +564,7 @@ def get_capstyle(self):
570564

571565
def set_joinstyle(self, js):
572566
"""
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).
575568
576569
Parameters
577570
----------
@@ -588,28 +581,26 @@ def get_joinstyle(self):
588581

589582
@staticmethod
590583
def _bcast_lwls(linewidths, dashes):
591-
'''Internal helper function to broadcast + scale ls/lw
584+
"""
585+
Internal helper function to broadcast + scale ls/lw
592586
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.
598591
599592
Parameters
600593
----------
601594
linewidths : list
602595
line widths of collection
603-
604596
dashes : list
605597
dash specification (offset, (dash pattern tuple))
606598
607599
Returns
608600
-------
609601
linewidths, dashes : list
610602
Will be the same length, dashes are scaled by paired linewidth
611-
612-
'''
603+
"""
613604
if mpl.rcParams['_internal.classic_mode']:
614605
return linewidths, dashes
615606
# make sure they are the same length so we can zip them
@@ -723,26 +714,20 @@ def _set_edgecolor(self, c):
723714

724715
def set_edgecolor(self, c):
725716
"""
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.
734718
735719
Parameters
736720
----------
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.
738724
"""
739725
self._original_edgecolor = c
740726
self._set_edgecolor(c)
741727

742728
def set_alpha(self, alpha):
743729
"""
744-
Set the alpha tranparencies of the collection. *alpha* must be
745-
a float or *None*.
730+
Set the alpha tranparencies of the collection.
746731
747732
Parameters
748733
----------
@@ -765,10 +750,7 @@ def get_linestyle(self):
765750
return self._linestyles
766751

767752
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."""
772754
if self._A is None:
773755
return
774756
if self._A.ndim > 1:
@@ -861,7 +843,6 @@ def set_sizes(self, sizes, dpi=72.0):
861843
sizes : ndarray or None
862844
The size to set for each element of the collection. The
863845
value is the 'area' of the element.
864-
865846
dpi : float
866847
The dpi of the canvas. Defaults to 72.0.
867848
"""
@@ -963,7 +944,7 @@ def set_verts(self, verts, closed=True):
963944
set_paths = set_verts
964945

965946
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."""
967948
if len(verts) != len(codes):
968949
raise ValueError("'codes' must be a 1D list or array "
969950
"with the same length of 'verts'")
@@ -1025,9 +1006,9 @@ def span_where(x, ymin, ymax, where, **kwargs):
10251006

10261007
class RegularPolyCollection(_CollectionWithSizes):
10271008
"""Draw a collection of regular polygons with *numsides*."""
1028-
_path_generator = mpath.Path.unit_regular_polygon
10291009

1030-
_factor = CIRCLE_AREA_FACTOR
1010+
_path_generator = mpath.Path.unit_regular_polygon
1011+
_factor = np.pi ** (-1/2)
10311012

10321013
@docstring.dedent_interpd
10331014
def __init__(self,
@@ -1089,16 +1070,12 @@ def draw(self, renderer):
10891070

10901071

10911072
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."""
10951074
_path_generator = mpath.Path.unit_regular_star
10961075

10971076

10981077
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."""
11021079
_path_generator = mpath.Path.unit_regular_asterisk
11031080

11041081

@@ -1295,13 +1272,13 @@ def get_color(self):
12951272

12961273

12971274
class EventCollection(LineCollection):
1298-
'''
1275+
"""
12991276
A collection of discrete events.
13001277
13011278
The events are given by a 1-dimensional array, usually the position of
13021279
something along an axis, such as time or length. They do not have an
13031280
amplitude and are displayed as vertical or horizontal parallel bars.
1304-
'''
1281+
"""
13051282

13061283
_edge_default = True
13071284

@@ -1542,10 +1519,9 @@ def get_color(self):
15421519

15431520

15441521
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)
15491525

15501526
@docstring.dedent_interpd
15511527
def __init__(self, sizes, **kwargs):
@@ -1562,9 +1538,8 @@ def __init__(self, sizes, **kwargs):
15621538

15631539

15641540
class EllipseCollection(Collection):
1565-
"""
1566-
A collection of ellipses, drawn using splines.
1567-
"""
1541+
"""A collection of ellipses, drawn using splines."""
1542+
15681543
@docstring.dedent_interpd
15691544
def __init__(self, widths, heights, angles, units='points', **kwargs):
15701545
"""
@@ -1607,9 +1582,8 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
16071582
self._paths = [mpath.Path.unit_circle()]
16081583

16091584
def _set_transforms(self):
1610-
"""
1611-
Calculate transforms immediately before drawing.
1612-
"""
1585+
"""Calculate transforms immediately before drawing."""
1586+
16131587
ax = self.axes
16141588
fig = self.figure
16151589

@@ -1712,11 +1686,9 @@ def set_paths(self, patches):
17121686

17131687
class TriMesh(Collection):
17141688
"""
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.
17171690
1718-
A triangular mesh is a :class:`~matplotlib.tri.Triangulation`
1719-
object.
1691+
A triangular mesh is a `~matplotlib.tri.Triangulation` object.
17201692
"""
17211693
def __init__(self, triangulation, **kwargs):
17221694
Collection.__init__(self, **kwargs)
@@ -1743,11 +1715,10 @@ def set_paths(self):
17431715
@staticmethod
17441716
def convert_mesh_to_paths(tri):
17451717
"""
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.
17491719
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.
17511722
"""
17521723
triangles = tri.get_masked_triangles()
17531724
verts = np.stack((tri.x[triangles], tri.y[triangles]), axis=-1)
@@ -1839,11 +1810,10 @@ def get_datalim(self, transData):
18391810
@staticmethod
18401811
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
18411812
"""
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.
18451814
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.
18471817
"""
18481818
if isinstance(coordinates, np.ma.MaskedArray):
18491819
c = coordinates.data
@@ -1863,7 +1833,7 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
18631833
"""
18641834
Converts a given mesh into a sequence of triangles, each point
18651835
with its own color. This is useful for experiments using
1866-
`draw_qouraud_triangle`.
1836+
`draw_gouraud_triangle`.
18671837
"""
18681838
if isinstance(coordinates, np.ma.MaskedArray):
18691839
p = coordinates.data

0 commit comments

Comments
 (0)
0