@@ -1083,53 +1083,84 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
1083
1083
linelengths = 1 , linewidths = None , colors = None ,
1084
1084
linestyles = 'solid' , ** kwargs ):
1085
1085
"""
1086
- Plot identical parallel lines at specific positions.
1086
+ Plot identical parallel lines at the given positions.
1087
1087
1088
- Plot parallel lines at the given positions. positions should be a 1D
1089
- or 2D array-like object, with each row corresponding to a row or column
1090
- of lines.
1088
+ *positions* should be a 1D or 2D array-like object, with each row
1089
+ corresponding to a row or column of lines.
1091
1090
1092
1091
This type of plot is commonly used in neuroscience for representing
1093
- neural events, where it is commonly called a spike raster, dot raster,
1092
+ neural events, where it is usually called a spike raster, dot raster,
1094
1093
or raster plot.
1095
1094
1096
1095
However, it is useful in any situation where you wish to show the
1097
1096
timing or position of multiple sets of discrete events, such as the
1098
1097
arrival times of people to a business on each day of the month or the
1099
1098
date of hurricanes each year of the last century.
1100
1099
1101
- *orientation* : [ 'horizontal' | 'vertical' ]
1102
- 'horizontal' : the lines will be vertical and arranged in rows
1103
- 'vertical' : lines will be horizontal and arranged in columns
1100
+ Parameters
1101
+ ----------
1102
+ positions : 1D or 2D array-like object
1103
+ Each value is an event. If *positions* is a 2D array-like, each
1104
+ row corresponds to a row or a column of lines (depending on the
1105
+ *orientation* parameter).
1106
+
1107
+ orientation : {'horizontal', 'vertical'}, optional
1108
+ Controls the direction of the event collections:
1109
+
1110
+ - 'horizontal' : the lines are arranged horizontally in rows,
1111
+ and are vertical.
1112
+ - 'vertical' : the lines are arranged vertically in columns,
1113
+ and are horizontal.
1114
+
1115
+ lineoffsets : scalar or sequence of scalars, optional, default: 1
1116
+ The offset of the center of the lines from the origin, in the
1117
+ direction orthogonal to *orientation*.
1118
+
1119
+ linelengths : scalar or sequence of scalars, optional, default: 1
1120
+ The total height of the lines (i.e. the lines stretches from
1121
+ ``lineoffset - linelength/2`` to ``lineoffset + linelength/2``).
1122
+
1123
+ linewidths : scalar, scalar sequence or None, optional, default: None
1124
+ The line width(s) of the event lines, in points. If it is None,
1125
+ defaults to its rcParams setting.
1126
+
1127
+ colors : color, sequence of colors or None, optional, default: None
1128
+ The color(s) of the event lines. If it is None, defaults to its
1129
+ rcParams setting.
1104
1130
1105
- *lineoffsets* :
1106
- A float or array-like containing floats.
1131
+ linestyles : str or tuple or a sequence of such values, optional
1132
+ Default is 'solid'. Valid strings are ['solid', 'dashed',
1133
+ 'dashdot', 'dotted', '-', '--', '-.', ':']. Dash tuples
1134
+ should be of the form::
1107
1135
1108
- *linelengths* :
1109
- A float or array-like containing floats.
1136
+ (offset, onoffseq),
1110
1137
1111
- *linewidths* :
1112
- A float or array-like containing floats .
1138
+ where *onoffseq* is an even length tuple of on and off ink
1139
+ in points .
1113
1140
1114
- *colors*
1115
- must be a sequence of RGBA tuples (e.g., arbitrary color
1116
- strings, etc, not allowed) or a list of such sequences
1141
+ **kwargs : optional
1142
+ Other keyword arguments are line collection properties. See
1143
+ :class:`~matplotlib.collections.LineCollection` for a list of
1144
+ the valid properties.
1117
1145
1118
- *linestyles* :
1119
- [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ] or an array of these
1120
- values
1146
+ Returns
1147
+ -------
1121
1148
1122
- For linelengths, linewidths, colors, and linestyles, if only a single
1123
- value is given, that value is applied to all lines. If an array-like
1124
- is given, it must have the same length as positions, and each value
1125
- will be applied to the corresponding row or column in positions.
1149
+ A list of :class:`matplotlib.collections.EventCollection` objects that
1150
+ were added.
1126
1151
1127
- Returns a list of :class:`matplotlib.collections.EventCollection`
1128
- objects that were added.
1152
+ Notes
1153
+ -----
1129
1154
1130
- kwargs are :class:`~matplotlib.collections.LineCollection` properties:
1155
+ For *linelengths*, *linewidths*, *colors*, and *linestyles*, if only
1156
+ a single value is given, that value is applied to all lines. If an
1157
+ array-like is given, it must have the same length as *positions*, and
1158
+ each value will be applied to the corresponding row of the array.
1131
1159
1132
- %(LineCollection)s
1160
+ Example
1161
+ -------
1162
+
1163
+ .. plot:: mpl_examples/pylab_examples/eventplot_demo.py
1133
1164
"""
1134
1165
self ._process_unit_info (xdata = positions ,
1135
1166
ydata = [lineoffsets , linelengths ],
@@ -1181,6 +1212,15 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
1181
1212
lineoffsets = [None ]
1182
1213
if len (colors ) == 0 :
1183
1214
colors = [None ]
1215
+ try :
1216
+ # Early conversion of the colors into RGBA values to take care
1217
+ # of cases like colors='0.5' or colors='C1'. (Issue #8193)
1218
+ colors = mcolors .to_rgba_array (colors )
1219
+ except ValueError :
1220
+ # Will fail if any element of *colors* is None. But as long
1221
+ # as len(colors) == 1 or len(positions), the rest of the
1222
+ # code should process *colors* properly.
1223
+ pass
1184
1224
1185
1225
if len (lineoffsets ) == 1 and len (positions ) != 1 :
1186
1226
lineoffsets = np .tile (lineoffsets , len (positions ))
0 commit comments