Skip to content

Update docs of PolyCollection #15790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def get_visible(self):
return self._visible

def get_animated(self):
"""Return the animated state."""
"""Return whether the artist is animated."""
return self._animated

def get_in_layout(self):
Expand Down Expand Up @@ -1072,7 +1072,7 @@ def sticky_edges(self):
return self._sticky_edges

def update_from(self, other):
'Copy properties from *other* to *self*.'
""""Copy properties from *other* to *self*."""
self._transform = other._transform
self._transformSet = other._transformSet
self._visible = other._visible
Expand Down
8 changes: 5 additions & 3 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,17 @@ def set_array(self, A):
self.update_dict['array'] = True

def get_array(self):
'Return the array'
"""Return the data array."""
return self._A

def get_cmap(self):
'return the colormap'
"""Return the `.Colormap` instance."""
return self.cmap

def get_clim(self):
'return the min, max of the color limits for image scaling'
"""
Return the values (min, max) that are mapped to the colormap limits.
"""
return self.norm.vmin, self.norm.vmax

def set_clim(self, vmin=None, vmax=None):
Expand Down
93 changes: 56 additions & 37 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,30 +1051,44 @@ class PolyCollection(_CollectionWithSizes):
@docstring.dedent_interpd
def __init__(self, verts, sizes=None, closed=True, **kwargs):
"""
*verts* is a sequence of ( *verts0*, *verts1*, ...) where
*verts_i* is a sequence of *xy* tuples of vertices, or an
equivalent :mod:`numpy` array of shape (*nv*, 2).

*sizes* is *None* (default) or a sequence of floats that
scale the corresponding *verts_i*. The scaling is applied
before the Artist master transform; if the latter is an identity
transform, then the overall scaling is such that if
*verts_i* specify a unit square, then *sizes_i* is the area
of that square in points^2.
If len(*sizes*) < *nv*, the additional values will be
taken cyclically from the array.

*closed*, when *True*, will explicitly close the polygon.

%(Collection)s
Parameters
----------
verts : sequence
The sequence of polygons [*verts0*, *verts1*, ...] where each
element *verts_i* defines the vertices of polygon *i* as a 2D
array-like of of shape (M, 2).
sizes : array-like, default: None
Squared scaling factors for the polygons. The coordinates of each
polygon *verts_i* are multiplied by the square-root of the
corresponding entry in *sizes* (i.e., *sizes* specify the scaling
of areas). The scaling is applied before the Artist master
transform. If *sizes* is shorter than *verts*, the additional
values will be taken cyclically from the *sizes*.
closed : bool, default: True
Whether the polygon should be closed by adding a CLOSEPOLY
connection at the end.
**kwargs
%(Collection)s
"""
Collection.__init__(self, **kwargs)
self.set_sizes(sizes)
self.set_verts(verts, closed)
self.stale = True

def set_verts(self, verts, closed=True):
'''This allows one to delay initialization of the vertices.'''
"""
Set the vertices of the polygons.

Parameters
----------
verts : sequence
The sequence of polygons [*verts0*, *verts1*, ...] where each
element *verts_i* defines the vertices of polygon *i* as a 2D
array-like of of shape (M, 2).
closed : bool, default: True
Whether the polygon should be closed by adding a CLOSEPOLY
connection at the end.
"""
if isinstance(verts, np.ma.MaskedArray):
verts = verts.astype(float).filled(np.nan)
# This is much faster than having Path do it one at a time.
Expand Down Expand Up @@ -1122,13 +1136,14 @@ class BrokenBarHCollection(PolyCollection):
@docstring.dedent_interpd
def __init__(self, xranges, yrange, **kwargs):
"""
*xranges*
sequence of (*xmin*, *xwidth*)

*yrange*
*ymin*, *ywidth*

%(Collection)s
Parameters
----------
xranges : sequence of (float, float)
The sequence of (left-edge-position, width) pairs for each bar.
yrange : (float, float)
The (lower-edge, height) common to all bars.
**kwargs
%(Collection)s
"""
ymin, ywidth = yrange
ymax = ymin + ywidth
Expand Down Expand Up @@ -1162,7 +1177,7 @@ def span_where(x, ymin, ymax, where, **kwargs):


class RegularPolyCollection(_CollectionWithSizes):
"""Draw a collection of regular polygons with *numsides*."""
"""A collection of n-sided regular polygons."""

_path_generator = mpath.Path.unit_regular_polygon
_factor = np.pi ** (-1/2)
Expand All @@ -1174,20 +1189,24 @@ def __init__(self,
sizes=(1,),
**kwargs):
"""
*numsides*
the number of sides of the polygon

*rotation*
the rotation of the polygon in radians

*sizes*
gives the area of the circle circumscribing the
regular polygon in points^2
Parameters
----------
numsides : int
The number of sides of the polygon.
rotation : float
The rotation of the polygon in radians.
sizes : tuple of float
The area of the circle circumscribing the polygon in points^2.

%(Collection)s
Other Parameters
----------------
**kwargs
Other keyword arguments.
%(Collection)s

Example: see :doc:`/gallery/event_handling/lasso_demo` for a
complete example::
Examples
--------
See :doc:`/gallery/event_handling/lasso_demo` for a complete example::

offsets = np.random.rand(20, 2)
facecolors = [cm.jet(x) for x in np.random.rand(20)]
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def contains_points(self, points, radius=None):
radius)

def update_from(self, other):
"""Updates this `.Patch` from the properties of *other*."""
# docstring inherited.
artist.Artist.update_from(self, other)
# For some properties we don't need or don't want to go through the
# getters/setters, so we just copy them directly.
Expand Down