@@ -200,9 +200,11 @@ def process(self, s, *args, **kwargs):
200
200
201
201
class silent_list (list ):
202
202
"""
203
- override repr when returning a list of matplotlib artists to
204
- prevent long, meaningless output. This is meant to be used for a
205
- homogeneous list of a given type
203
+ A list with a short ``repr()``.
204
+
205
+ This is meant to be used for a homogeneous list of a given type. In
206
+ particular, this is intended to be used for returning a list of artists
207
+ to prevent long, meaningless output.
206
208
"""
207
209
def __init__ (self , type , seq = None ):
208
210
self .type = type
@@ -226,7 +228,7 @@ def __setstate__(self, state):
226
228
class IgnoredKeywordWarning (UserWarning ):
227
229
"""
228
230
A class for issuing warnings about keyword arguments that will be ignored
229
- by matplotlib
231
+ by Matplotlib.
230
232
"""
231
233
pass
232
234
@@ -235,7 +237,7 @@ def local_over_kwdict(local_var, kwargs, *keys):
235
237
"""
236
238
Enforces the priority of a local variable over potentially conflicting
237
239
argument(s) from a kwargs dict. The following possible output values are
238
- considered in order of priority:
240
+ considered in order of priority::
239
241
240
242
local_var > kwargs[keys[0]] > ... > kwargs[keys[-1]]
241
243
@@ -245,26 +247,26 @@ def local_over_kwdict(local_var, kwargs, *keys):
245
247
246
248
Parameters
247
249
----------
248
- local_var : any object
249
- The local variable (highest priority)
250
+ local_var : any object
251
+ The local variable (highest priority).
250
252
251
- kwargs : dict
252
- Dictionary of keyword arguments; modified in place
253
+ kwargs : dict
254
+ Dictionary of keyword arguments; modified in place.
253
255
254
- keys : str(s)
255
- Name(s) of keyword arguments to process, in descending order of
256
- priority
256
+ keys : str(s)
257
+ Name(s) of keyword arguments to process, in descending order of
258
+ priority.
257
259
258
260
Returns
259
261
-------
260
- out : any object
261
- Either local_var or one of kwargs[key] for key in keys
262
+ out : any object
263
+ Either local_var or one of kwargs[key] for key in keys.
262
264
263
265
Raises
264
266
------
265
- IgnoredKeywordWarning
266
- For each key in keys that is removed from kwargs but not used as
267
- the output value
267
+ IgnoredKeywordWarning
268
+ For each key in keys that is removed from kwargs but not used as
269
+ the output value.
268
270
269
271
"""
270
272
out = local_var
@@ -447,7 +449,7 @@ def _get_data_path(*args):
447
449
448
450
def flatten (seq , scalarp = is_scalar_or_string ):
449
451
"""
450
- Return a generator of flattened nested containers
452
+ Return a generator of flattened nested containers.
451
453
452
454
For example:
453
455
@@ -526,9 +528,12 @@ def dedent(s):
526
528
527
529
class maxdict (dict ):
528
530
"""
529
- A dictionary with a maximum size; this doesn't override all the
530
- relevant methods to constrain the size, just setitem, so use with
531
- caution
531
+ A dictionary with a maximum size.
532
+
533
+ Notes
534
+ -----
535
+ This doesn't override all the relevant methods to constrain the size,
536
+ just ``__setitem__``, so use with caution.
532
537
"""
533
538
def __init__ (self , maxsize ):
534
539
dict .__init__ (self )
@@ -702,15 +707,18 @@ def safe_masked_invalid(x, copy=False):
702
707
703
708
def print_cycles (objects , outstream = sys .stdout , show_progress = False ):
704
709
"""
705
- *objects*
706
- A list of objects to find cycles in. It is often useful to
707
- pass in gc.garbage to find the cycles that are preventing some
708
- objects from being garbage collected.
710
+ Print loops of cyclic references in the given *objects*.
709
711
710
- *outstream*
711
- The stream for output .
712
+ It is often useful to pass in ``gc.garbage`` to find the cycles that are
713
+ preventing some objects from being garbage collected .
712
714
713
- *show_progress*
715
+ Parameters
716
+ ----------
717
+ objects
718
+ A list of objects to find cycles in.
719
+ outstream
720
+ The stream for output.
721
+ show_progress : bool
714
722
If True, print the number of objects reached as they are found.
715
723
"""
716
724
import gc
@@ -868,17 +876,18 @@ def simple_linear_interpolation(a, steps):
868
876
"""
869
877
Resample an array with ``steps - 1`` points between original point pairs.
870
878
879
+ Along each column of *a*, ``(steps - 1)`` points are introduced between
880
+ each original values; the values are linearly interpolated.
881
+
871
882
Parameters
872
883
----------
873
884
a : array, shape (n, ...)
874
885
steps : int
875
886
876
887
Returns
877
888
-------
878
- array, shape ``((n - 1) * steps + 1, ...)``
879
-
880
- Along each column of *a*, ``(steps - 1)`` points are introduced between
881
- each original values; the values are linearly interpolated.
889
+ array
890
+ shape ``((n - 1) * steps + 1, ...)``
882
891
"""
883
892
fps = a .reshape ((len (a ), - 1 ))
884
893
xp = np .arange (len (a )) * steps
@@ -1246,8 +1255,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
1246
1255
1247
1256
def contiguous_regions (mask ):
1248
1257
"""
1249
- Return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
1250
- True and we cover all such regions
1258
+ Return a list of (ind0, ind1) such that `` mask[ind0:ind1].all()`` is
1259
+ True and we cover all such regions.
1251
1260
"""
1252
1261
mask = np .asarray (mask , dtype = bool )
1253
1262
@@ -1271,8 +1280,12 @@ def contiguous_regions(mask):
1271
1280
1272
1281
1273
1282
def is_math_text (s ):
1274
- # Did we find an even number of non-escaped dollar signs?
1275
- # If so, treat is as math text.
1283
+ """
1284
+ Returns whether the string *s* contains math expressions.
1285
+
1286
+ This is done by checking whether *s* contains an even number of
1287
+ non-escaped dollar signs.
1288
+ """
1276
1289
s = str (s )
1277
1290
dollar_count = s .count (r'$' ) - s .count (r'\$' )
1278
1291
even_dollars = (dollar_count > 0 and dollar_count % 2 == 0 )
@@ -1333,10 +1346,14 @@ def _reshape_2D(X, name):
1333
1346
def violin_stats (X , method , points = 100 , quantiles = None ):
1334
1347
"""
1335
1348
Returns a list of dictionaries of data which can be used to draw a series
1336
- of violin plots. See the `Returns` section below to view the required keys
1337
- of the dictionary. Users can skip this function and pass a user-defined set
1338
- of dictionaries to the `axes.vplot` method instead of using Matplotlib to
1339
- do the calculations.
1349
+ of violin plots.
1350
+
1351
+ See the Returns section below to view the required keys of the dictionary.
1352
+
1353
+ Users can skip this function and pass a user-defined set of dictionaries
1354
+ with the same keys to `~.axes.Axes.violinplot` instead of using Matplotlib
1355
+ to do the calculations. See the *Returns* section below for the keys
1356
+ that must be present in the dictionaries.
1340
1357
1341
1358
Parameters
1342
1359
----------
@@ -1350,7 +1367,7 @@ def violin_stats(X, method, points=100, quantiles=None):
1350
1367
return a vector of the values of the KDE evaluated at the values
1351
1368
specified in coords.
1352
1369
1353
- points : scalar , default = 100
1370
+ points : int , default = 100
1354
1371
Defines the number of points to evaluate each of the gaussian kernel
1355
1372
density estimates at.
1356
1373
@@ -1362,8 +1379,9 @@ def violin_stats(X, method, points=100, quantiles=None):
1362
1379
1363
1380
Returns
1364
1381
-------
1365
- A list of dictionaries containing the results for each column of data.
1366
- The dictionaries contain at least the following:
1382
+ vpstats : list of dict
1383
+ A list of dictionaries containing the results for each column of data.
1384
+ The dictionaries contain at least the following:
1367
1385
1368
1386
- coords: A list of scalars containing the coordinates this particular
1369
1387
kernel density estimate was evaluated at.
@@ -1448,7 +1466,7 @@ def pts_to_prestep(x, *args):
1448
1466
1449
1467
Examples
1450
1468
--------
1451
- >> x_s, y1_s, y2_s = pts_to_prestep(x, y1, y2)
1469
+ >>> x_s, y1_s, y2_s = pts_to_prestep(x, y1, y2)
1452
1470
"""
1453
1471
steps = np .zeros ((1 + len (args ), max (2 * len (x ) - 1 , 0 )))
1454
1472
# In all `pts_to_*step` functions, only assign *once* using `x` and `args`,
@@ -1486,7 +1504,7 @@ def pts_to_poststep(x, *args):
1486
1504
1487
1505
Examples
1488
1506
--------
1489
- >> x_s, y1_s, y2_s = pts_to_poststep(x, y1, y2)
1507
+ >>> x_s, y1_s, y2_s = pts_to_poststep(x, y1, y2)
1490
1508
"""
1491
1509
steps = np .zeros ((1 + len (args ), max (2 * len (x ) - 1 , 0 )))
1492
1510
steps [0 , 0 ::2 ] = x
@@ -1522,7 +1540,7 @@ def pts_to_midstep(x, *args):
1522
1540
1523
1541
Examples
1524
1542
--------
1525
- >> x_s, y1_s, y2_s = pts_to_midstep(x, y1, y2)
1543
+ >>> x_s, y1_s, y2_s = pts_to_midstep(x, y1, y2)
1526
1544
"""
1527
1545
steps = np .zeros ((1 + len (args ), 2 * len (x )))
1528
1546
x = np .asanyarray (x )
@@ -1543,19 +1561,19 @@ def pts_to_midstep(x, *args):
1543
1561
1544
1562
def index_of (y ):
1545
1563
"""
1546
- A helper function to get the index of an input to plot
1547
- against if x values are not explicitly given.
1564
+ A helper function to create reasonable x values for the given *y*.
1565
+
1566
+ This is used for plotting (x, y) if x values are not explicitly given.
1548
1567
1549
- Tries to get ` y.index` (works if this is a pd .Series), if that
1550
- fails, return np.arange(y.shape[0]) .
1568
+ First try `` y.index`` (assuming *y* is a `pandas .Series` ), if that
1569
+ fails, use ``range(len(y))`` .
1551
1570
1552
1571
This will be extended in the future to deal with more types of
1553
1572
labeled data.
1554
1573
1555
1574
Parameters
1556
1575
----------
1557
1576
y : scalar or array-like
1558
- The proposed y-value
1559
1577
1560
1578
Returns
1561
1579
-------
@@ -1570,6 +1588,12 @@ def index_of(y):
1570
1588
1571
1589
1572
1590
def safe_first_element (obj ):
1591
+ """
1592
+ Return the first element in *obj*.
1593
+
1594
+ This is an type-independent way of obtaining the first element, supporting
1595
+ both index access and the iterator protocol.
1596
+ """
1573
1597
if isinstance (obj , collections .abc .Iterator ):
1574
1598
# needed to accept `array.flat` as input.
1575
1599
# np.flatiter reports as an instance of collections.Iterator
@@ -1586,27 +1610,33 @@ def safe_first_element(obj):
1586
1610
1587
1611
1588
1612
def sanitize_sequence (data ):
1589
- """Converts dictview object to list"""
1613
+ """
1614
+ Convert dictview objects to list. Other inputs are returned unchanged.
1615
+ """
1590
1616
return (list (data ) if isinstance (data , collections .abc .MappingView )
1591
1617
else data )
1592
1618
1593
1619
1594
1620
def normalize_kwargs (kw , alias_mapping = None , required = (), forbidden = (),
1595
1621
allowed = None ):
1596
- """Helper function to normalize kwarg inputs
1622
+ """
1623
+ Helper function to normalize kwarg inputs.
1597
1624
1598
1625
The order they are resolved are:
1599
1626
1600
- 1. aliasing
1601
- 2. required
1602
- 3. forbidden
1603
- 4. allowed
1627
+ 1. aliasing
1628
+ 2. required
1629
+ 3. forbidden
1630
+ 4. allowed
1604
1631
1605
1632
This order means that only the canonical names need appear in
1606
- ` allowed`, ` forbidden`, ` required`
1633
+ * allowed*, * forbidden*, * required*.
1607
1634
1608
1635
Parameters
1609
1636
----------
1637
+ kw : dict
1638
+ A dict of keyword arguments.
1639
+
1610
1640
alias_mapping : dict or Artist subclass or Artist instance, optional
1611
1641
A mapping between a canonical name to a list of
1612
1642
aliases, in order of precedence from lowest to highest.
@@ -1617,17 +1647,17 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
1617
1647
If an Artist subclass or instance is passed, use its properties alias
1618
1648
mapping.
1619
1649
1620
- required : iterable , optional
1621
- A tuple of fields that must be in kwargs .
1650
+ required : list of str , optional
1651
+ A list of keys that must be in *kws* .
1622
1652
1623
- forbidden : iterable , optional
1624
- A list of keys which may not be in kwargs
1653
+ forbidden : list of str , optional
1654
+ A list of keys which may not be in *kw*.
1625
1655
1626
- allowed : tuple , optional
1627
- A tuple of allowed fields. If this not None, then raise if
1628
- `kw` contains any keys not in the union of ` required`
1629
- and ` allowed` . To allow only the required fields pass in
1630
- `` ()`` for `allowed`
1656
+ allowed : list of str , optional
1657
+ A list of allowed fields. If this not None, then raise if
1658
+ *kw* contains any keys not in the union of * required*
1659
+ and * allowed* . To allow only the required fields pass in
1660
+ an empty tuple ``allowed= ()``.
1631
1661
1632
1662
Raises
1633
1663
------
0 commit comments