Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Convert LineCollection docstring to numpydoc #9781

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 2 commits into from
Nov 28, 2017
Merged
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
78 changes: 47 additions & 31 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,29 +1171,52 @@ def __init__(self, segments, # Can be None.
**kwargs
):
"""
*segments*
a sequence of (*line0*, *line1*, *line2*), where::
Parameters
----------
segments :
A sequence of (*line0*, *line1*, *line2*), where::

linen = (x0, y0), (x1, y1), ... (xm, ym)

or the equivalent numpy array with two columns. Each line
can be a different length.

*colors*
must be a sequence of RGBA tuples (e.g., arbitrary color
colors : sequence, optional
A sequence of RGBA tuples (e.g., arbitrary color
strings, etc, not allowed).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still true? I am wondering because the following

import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
plt.ion()

coll = LineCollection([[[0, 0], [1, 1]], [[0, 1], [1, 0]]],
                      colors=["tab:gray", "tab:green"])

fig, ax = plt.subplots()
ax.add_collection(coll)

print("Click on the figure to change the colors")
plt.ginput(1)

coll.set_color(["tab:red", "tab:purple"])

seems to be fine, even though the colors are given as a list of arbitrary strings when instantiating the line collection.


*antialiaseds*
must be a sequence of ones or zeros
antialiaseds : sequence, optional
A sequence of ones or zeros.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does someone knows what this option actually does? At least enough to suggest a sentence giving a rough idea of its effect or purpose ^^.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it controls if any given line segment is anti-aliased when drawn. This gets handed through to the gc object and may or may not be respected by all of the backends. I think it should be read as (antialiased (s) like linestyle (s)).


*linestyles* [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ]
a string or dash tuple. The dash tuple is::
linestyles : string, tuple, optional
Either one of [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ], or
a dash tuple. The dash tuple is::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the short names are also fine (I mean "-", "--", "-.", ":")? (And possibly some other exotic options sometimes accepted by some methods and classes related to lines)


(offset, onoffseq),
(offset, onoffseq)

where *onoffseq* is an even length tuple of on and off ink
where ``onoffseq`` is an even length tuple of on and off ink
in points.

norm : Normalize, optional
`~.colors.Normalize` instance.

cmap : string or Colormap, optional
Colormap name or `~.colors.Colormap` instance.

pickradius : float, optional
The tolerance in points for mouse clicks picking a line.
Default is 5 pt.

zorder : int, optional
zorder of the LineCollection. Default is 2.

facecolors : optional
The facecolors of the LineCollection. Default is 'none'.
Setting to a value other than 'none' will lead to a filled
polygon being drawn between points on each line.

Notes
-----
If *linewidths*, *colors*, or *antialiaseds* is None, they
default to their rcParams setting, in sequence form.

Expand All @@ -1210,22 +1233,6 @@ def __init__(self, segments, # Can be None.
and this value will be added cumulatively to each successive
segment, so as to produce a set of successively offset curves.

*norm*
None (optional for :class:`matplotlib.cm.ScalarMappable`)
*cmap*
None (optional for :class:`matplotlib.cm.ScalarMappable`)

*pickradius* is the tolerance for mouse clicks picking a line.
The default is 5 pt.

*zorder*
The zorder of the LineCollection. Default is 2

*facecolors*
The facecolors of the LineCollection. Default is 'none'
Setting to a value other than 'none' will lead to a filled
polygon being drawn between points on each line.

The use of :class:`~matplotlib.cm.ScalarMappable` is optional.
If the :class:`~matplotlib.cm.ScalarMappable` array
:attr:`~matplotlib.cm.ScalarMappable._A` is not None (i.e., a call to
Expand Down Expand Up @@ -1278,6 +1285,13 @@ def set_segments(self, segments):
set_paths = set_segments

def get_segments(self):
"""
Returns
-------
segments : list
List of segments in the LineCollection. Each list item contains an
array of vertices.
"""
segments = []

for path in self._paths:
Expand All @@ -1302,12 +1316,14 @@ def _add_offsets(self, segs):

def set_color(self, c):
"""
Set the color(s) of the line collection. *c* can be a
matplotlib color arg (all patches have same color), or a
sequence or rgba tuples; if it is a sequence the patches will
cycle through the sequence.
Set the color(s) of the LineCollection.

ACCEPTS: matplotlib color arg or sequence of rgba tuples
Parameters
----------
c :
Matplotlib color argument (all patches have same color), or a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, as for the colors parameter in the class constructor, it seems to me that one does not have anymore to use exclusively an RGBA sequence to define every color independently. See the second half of the example that I gave above.

NB: looking at the former docstring (more precisely to the “ACCEPTS:...” part), I have the feeling that there was a typo in “... a sequence or of rgba tuples; ...”.

sequence or rgba tuples; if it is a sequence the patches will
cycle through the sequence.
"""
self.set_edgecolor(c)
self.stale = True
Expand Down