8000 'eventplot' and 'EventCollection' docstrings overhaul · matplotlib/matplotlib@f22d22d · GitHub
[go: up one dir, main page]

Skip to content

Commit f22d22d

Browse files
committed
'eventplot' and 'EventCollection' docstrings overhaul
1 parent 77a604c commit f22d22d

File tree

3 files changed

+81
-65
lines changed

3 files changed

+81
-65
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,55 +1091,72 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
10911091
linelengths=1, linewidths=None, colors=None,
10921092
linestyles='solid', **kwargs):
10931093
"""
1094-
Plot identical parallel lines at specific positions.
1094+
Plot identical parallel lines at the given positions.
10951095
1096-
Plot parallel lines at the given positions. positions should be a 1D
1097-
or 2D array-like object, with each row corresponding to a row or column
1098-
of lines.
1096+
*positions* should be a 1D or 2D array-like object, with each row
1097+
corresponding to a row or column of lines.
10991098
11001099
This type of plot is commonly used in neuroscience for representing
1101-
neural events, where it is commonly called a spike raster, dot raster,
1100+
neural events, where it is usually called a spike raster, dot raster,
11021101
or raster plot.
11031102
11041103
However, it is useful in any situation where you wish to show the
11051104
timing or position of multiple sets of discrete events, such as the
11061105
arrival times of people to a business on each day of the month or the
11071106
date of hurricanes each year of the last century.
11081107
1109-
*orientation* : [ 'horizontal' | 'vertical' ]
1110-
'horizontal' : the lines will be vertical and arranged in rows
1111-
'vertical' : lines will be horizontal and arranged in columns
1108+
Parameters
1109+
----------
1110+
positions : 1D or 2D array-like object.
1111+
Each value is an event. If *positions* is a 2D array-like, each
1112+
row corresponds to a row or a column of lines (depending on the
1113+
*orientation* parameter).
1114+
1115+
orientation : str [ 'horizontal' (default) | 'vertical' ], optional.
1116+
'horizontal' : the lines will be vertical and arranged in rows.
1117+
'vertical' : the lines will be horizontal and arranged in columns.
11121118
1113-
*lineoffsets* :
1114-
A float or array-like containing floats.
1119+
lineoffsets : scalar or sequence of scalars, optional. Default is 1.
1120+
The offset of the center of the lines from the origin.
11151121
1116-
*linelengths* :
1117-
A float or array-like containing floats.
1122+
linelengths : scalar or sequence of scalars, optional. Default is 1.
1123+
The total height of the lines (i.e. the lines stretches from
1124+
``lineoffset + linelength/2`` to ``lineoffset - linelength/2``).
11181125
1119-
*linewidths* :
1120-
A float or array-like containing floats.
1126+
linewidths : scalar, scalar sequence or None, optional. Default: None.
1127+
If it is None, defaults to its rcParams setting.
11211128
1122-
*colors*
1123-
must be a sequence of RGBA tuples (e.g., arbitrary color
1124-
strings, etc, not allowed) or a list of such sequences
1129+
colors : color, sequence of colors or None, optional. Default is None.
1130+
If it is None, defaults to its rcParams setting.
11251131
1126-
*linestyles* :
1127-
[ 'solid' | 'dashed' | 'dashdot' | 'dotted' ] or an array of these
1128-
values
1132+
linestyles : str or tuple or a sequence of such values, optional.
1133+
Default is 'solid'. Valid strings are [ 'solid' | 'dashed' |
1134+
'dashdot' | 'dotted' | '-' | '--' | '-.' | ':' ]. Dash tuples
1135+
have to follow::
11291136
1130-
For linelengths, linewidths, colors, and linestyles, if only a single
1131-
value is given, that value is applied to all lines. If an array-like
1132-
is given, it must have the same length as positions, and each value
1133-
will be applied to the corresponding row or column in positions.
1137+
(offset, onoffseq),
11341138
1135-
Returns a list of :class:`matplotlib.collections.EventCollection`
1136-
objects that were added.
1139+
where *onoffseq* is an even length tuple of on and off ink
1140+
in points.
1141+
1142+
For *linelengths*, *linewidths*, *colors*, and *linestyles*, if only
1143+
a single value is given, that value is applied to all lines. If an
1144+
array-like is given, it must have the same length as positions, and
1145+
each value will be applied to the corresponding row or column in
1146+
positions.
11371147
11381148
kwargs are :class:`~matplotlib.collections.LineCollection` properties:
11391149
11401150
%(LineCollection)s
11411151
1142-
**Example:**
1152+
Returns
1153+
-------
1154+
1155+
A list of :class:`matplotlib.collections.EventCollection` objects that
1156+
were added.
1157+
1158+
Example
1159+
-------
11431160
11441161
.. plot:: mpl_examples/pylab_examples/eventplot_demo.py
11451162
"""

lib/matplotlib/collections.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,9 @@ class EventCollection(LineCollection):
12431243
'''
12441244
A collection of discrete events.
12451245
1246-
An event is a 1-dimensional value, usually the position of something along
1247-
an axis, such as time or length. Events do not have an amplitude. They
1248-
are displayed as v
1246+
The events are a 1-dimensional array, usually the position of something
1247+
along an axis, such as time or length. The do not have an amplitude and
1248+
are displayed as vertical or horizontal parallel bars.
12491249
'''
12501250

12511251
_edge_default = True
@@ -1262,51 +1262,49 @@ def __init__(self,
12621262
**kwargs
12631263
):
12641264
"""
1265-
*positions*
1266-
a sequence of numerical values or a 1D numpy array. Can be None
1265+
Parameters
1266+
----------
1267+
positions : 1D array-like object or None.
1268+
Each value is an event.
12671269
1268-
*orientation* [ 'horizontal' | 'vertical' | None ]
1269-
defaults to 'horizontal' if not specified or None
1270+
orientation : [ None (default) | 'horizontal' | 'vertical'], optional.
1271+
The orientation of the **collection** (the event bars are along
1272+
the orthogonal direction). Defaults to 'horizontal' if not
1273+
specified or None.
12701274
1271-
*lineoffset*
1272-
a single numerical value, corresponding to the offset of the center
1273-
of the markers from the origin
1275+
lineoffset : scalar, optional. Default is 0.
1276+
The offset of the center of the markers from the origin.
12741277
1275-
*linelength*
1276-
a single numerical value, corresponding to the total height of the
1277-
marker (i.e. the marker stretches from lineoffset+linelength/2 to
1278-
lineoffset-linelength/2). Defaults to 1
1278+
linelength : scalar, optional. Default is 1.
1279+
The total height of the marker (i.e. the marker stretches from
1280+
``lineoffset + linelength/2`` to ``lineoffset - linelength/2``).
12791281
1280-
*linewidth*
1281-
a single numerical value
1282+
linewidth : scalar or None, optional. Default is None.
1283+
If it is None, defaults to its rcParams setting, in sequence form.
12821284
1283-
*color*
1284-
must be a sequence of RGBA tuples (e.g., arbitrary color
1285-
strings, etc, not allowed).
1285+
color : color, sequence of colors or None, optional. Default is None.
1286+
If it is None, defaults to its rcParams setting, in sequence form.
12861287
1287-
*linestyle* [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ]
1288+
linestyle : str or tuple, optional. Default is 'solid'.
1289+
If it is a string, it has to be among [ 'solid' | 'dashed' |
1290+
'dashdot' | 'dotted' | '-' | '--' | '-.' | ':' ]. If it is a dash
1291+
tuple, it has to be of the form::
12881292
1289-
*antialiased*
1290-
1 or 2
1293+
(offset, onoffseq),
12911294
1292-
If *linewidth*, *color*, or *antialiased* is None, they
1293-
default to their rcParams setting, in sequence form.
1295+
where *onoffseq* is an even length tuple of on and off ink
1296+
in points.
12941297
1295-
*norm*
1296-
None (optional for :class:`matplotlib.cm.ScalarMappable`)
1297-
*cmap*
1298-
None (optional for :class:`matplotlib.cm.ScalarMappable`)
1298+
antialiased : [None (default) | 1 | 2], optional.
1299+
If it is None, defaults to its rcParams setting, in sequence form.
12991300
1300-
*pickradius* is the tolerance for mouse clicks picking a line.
1301-
The default is 5 pt.
1301+
Additional kwargs of :class:`~matplotlib.collections.LineCollection`
1302+
can also be used:
13021303
1303-
The use of :class:`~matplotlib.cm.ScalarMappable` is optional.
1304-
If the :class:`~matplotlib.cm.ScalarMappable` array
1305-
:attr:`~matplotlib.cm.ScalarMappable._A` is not None (i.e., a call to
1306-
:meth:`~matplotlib.cm.ScalarMappable.set_array` has been made), at
1307-
draw time a call to scalar mappable will be made to set the colors.
1304+
%(LineCollection)s
13081305
1309-
**Example:**
1306+
Example
1307+
-------
13101308
13111309
.. plot:: mpl_examples/pylab_examples/eventcollection_demo.py
13121310
"""
@@ -1316,8 +1314,8 @@ def __init__(self,
13161314
if len(positions) == 0:
13171315
segments = []
13181316
elif hasattr(positions, 'ndim') and positions.ndim > 1:
1319-
raise ValueError('if positions is an ndarry it cannot have '
1320-
'dimensionality great than 1 ')
1317+
raise ValueError('if positions is an ndarray it cannot have '
1318+
'dimensionality strictly greater than 1 ')
13211319
elif (orientation is None or orientation.lower() == 'none' or
13221320
orientation.lower() == 'horizontal'):
13231321
positions.sort()

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,7 @@ def test_eventplot_colors():
29322932
for ax in axs.flat:
29332933
ax.set_xlim(-0.1, 3.1) # avoid having some events on the axes edges
29342934

2935+
29352936
@image_comparison(baseline_images=['test_eventplot_problem_kwargs'],
29362937
extensions=['png'], remove_text=True)
29372938
def test_eventplot_problem_kwargs():

0 commit comments

Comments
 (0)
0