@@ -200,9 +200,20 @@ 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 artists, so that they
206
+ don't cause long, meaningless output.
207
+
208
+ Instead of ::
209
+
210
+ [<matplotlib.lines.Line2D object at 0x7f5749fed3c8>,
211
+ <matplotlib.lines.Line2D object at 0x7f5749fed4e0>,
212
+ <matplotlib.lines.Line2D object at 0x7f5758016550>]
213
+
214
+ one will get ::
215
+
216
+ <a list of 3 Line2D objects>
206
217
"""
207
218
def __init__ (self , type , seq = None ):
208
219
self .type = type
@@ -226,7 +237,7 @@ def __setstate__(self, state):
226
237
class IgnoredKeywordWarning (UserWarning ):
227
238
"""
228
239
A class for issuing warnings about keyword arguments that will be ignored
229
- by matplotlib
240
+ by Matplotlib.
230
241
"""
231
242
pass
232
243
@@ -235,7 +246,7 @@ def local_over_kwdict(local_var, kwargs, *keys):
235
246
"""
236
247
Enforces the priority of a local variable over potentially conflicting
237
248
argument(s) from a kwargs dict. The following possible output values are
238
- considered in order of priority:
249
+ considered in order of priority::
239
250
240
251
local_var > kwargs[keys[0]] > ... > kwargs[keys[-1]]
241
252
@@ -245,26 +256,26 @@ def local_over_kwdict(local_var, kwargs, *keys):
245
256
246
257
Parameters
247
258
----------
248
- local_var : any object
249
- The local variable (highest priority)
259
+ local_var : any object
260
+ The local variable (highest priority).
250
261
251
- kwargs : dict
252
- Dictionary of keyword arguments; modified in place
262
+ kwargs : dict
263
+ Dictionary of keyword arguments; modified in place.
253
264
254
- keys : str(s)
255
- Name(s) of keyword arguments to process, in descending order of
256
- priority
265
+ keys : str(s)
266
+ Name(s) of keyword arguments to process, in descending order of
267
+ priority.
257
268
258
269
Returns
259
270
-------
260
- out : any object
261
- Either local_var or one of kwargs[key] for key in keys
271
+ out : any object
272
+ Either local_var or one of kwargs[key] for key in keys.
262
273
263
274
Raises
264
275
------
265
- IgnoredKeywordWarning
266
- For each key in keys that is removed from kwargs but not used as
267
- the output value
276
+ IgnoredKeywordWarning
277
+ For each key in keys that is removed from kwargs but not used as
278
+ the output value.
268
279
269
280
"""
270
281
out = local_var
@@ -447,7 +458,7 @@ def _get_data_path(*args):
447
458
448
459
def flatten (seq , scalarp = is_scalar_or_string ):
449
460
"""
450
- Return a generator of flattened nested containers
461
+ Return a generator of flattened nested containers.
451
462
452
463
For example:
453
464
@@ -526,9 +537,12 @@ def dedent(s):
526
537
527
538
class maxdict (dict ):
528
539
"""
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
540
+ A dictionary with a maximum size.
541
+
542
+ Notes
543
+ -----
544
+ This doesn't override all the relevant methods to constrain the size,
545
+ just ``__setitem__``, so use with caution.
532
546
"""
533
547
def __init__ (self , maxsize ):
534
548
dict .__init__ (self )
@@ -702,15 +716,18 @@ def safe_masked_invalid(x, copy=False):
702
716
703
717
def print_cycles (objects , outstream = sys .stdout , show_progress = False ):
704
718
"""
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.
719
+ Print loops of cyclic references in the given *objects*.
709
720
710
- *outstream*
711
- The stream for output .
721
+ It is often useful to pass in ``gc.garbage`` to find the cycles that are
722
+ preventing some objects from being garbage collected .
712
723
713
- *show_progress*
724
+ Parameters
725
+ ----------
726
+ objects
727
+ A list of objects to find cycles in.
728
+ outstream
729
+ The stream for output.
730
+ show_progress : bool
714
731
If True, print the number of objects reached as they are found.
715
732
"""
716
733
import gc
@@ -868,17 +885,18 @@ def simple_linear_interpolation(a, steps):
868
885
"""
869
886
Resample an array with ``steps - 1`` points between original point pairs.
870
887
888
+ Along each column of *a*, ``(steps - 1)`` points are introduced between
889
+ each original values; the values are linearly interpolated.
890
+
871
891
Parameters
872
892
----------
873
893
a : array, shape (n, ...)
874
894
steps : int
875
895
876
896
Returns
877
897
-------
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.
898
+ array
899
+ shape ``((n - 1) * steps + 1, ...)``
882
900
"""
883
901
fps = a .reshape ((len (a ), - 1 ))
884
902
xp = np .arange (len (a )) * steps
@@ -1246,8 +1264,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
1246
1264
1247
1265
def contiguous_regions (mask ):
1248
1266
"""
1249
- Return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
1250
- True and we cover all such regions
1267
+ Return a list of (ind0, ind1) such that `` mask[ind0:ind1].all()`` is
1268
+ True and we cover all such regions.
1251
1269
"""
1252
1270
mask = np .asarray (mask , dtype = bool )
1253
1271
@@ -1271,8 +1289,12 @@ def contiguous_regions(mask):
1271
1289
1272
1290
1273
1291
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.
1292
+ """
1293
+ Returns whether the string *s* contains math expressions.
1294
+
1295
+ This is done by checking whether *s* contains an even number of
1296
+ non-escaped dollar signs.
1297
+ """
1276
1298
s = str (s )
1277
1299
dollar_count = s .count (r'$' ) - s .count (r'\$' )
1278
1300
even_dollars = (dollar_count > 0 and dollar_count % 2 == 0 )
@@ -1333,10 +1355,14 @@ def _reshape_2D(X, name):
1333
1355
def violin_stats (X , method , points = 100 , quantiles = None ):
1334
1356
"""
1335
1357
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.
1358
+ of violin plots.
1359
+
1360
+ See the Returns section below to view the required keys of the dictionary.
1361
+
1362
+ Users can skip this function and pass a user-defined set of dictionaries
1363
+ with the same keys to `~.axes.Axes.violinplot` instead of using Matplotlib
1364
+ to do the calculations. See the *Returns* section below for the keys
1365
+ that must be present in the dictionaries.
1340
1366
1341
1367
Parameters
1342
1368
----------
@@ -1350,7 +1376,7 @@ def violin_stats(X, method, points=100, quantiles=None):
1350
1376
return a vector of the values of the KDE evaluated at the values
1351
1377
specified in coords.
1352
1378
1353
- points : scalar , default = 100
1379
+ points : int , default = 100
1354
1380
Defines the number of points to evaluate each of the gaussian kernel
1355
1381
density estimates at.
1356
1382
@@ -1362,8 +1388,9 @@ def violin_stats(X, method, points=100, quantiles=None):
1362
1388
1363
1389
Returns
1364
1390
-------
1365
- A list of dictionaries containing the results for each column of data.
1366
- The dictionaries contain at least the following:
1391
+ vpstats : list of dict
1392
+ A list of dictionaries containing the results for each column of data.
1393
+ The dictionaries contain at least the following:
1367
1394
1368
1395
- coords: A list of scalars containing the coordinates this particular
1369
1396
kernel density estimate was evaluated at.
@@ -1448,7 +1475,7 @@ def pts_to_prestep(x, *args):
1448
1475
1449
1476
Examples
1450
1477
--------
1451
- >> x_s, y1_s, y2_s = pts_to_prestep(x, y1, y2)
1478
+ >>> x_s, y1_s, y2_s = pts_to_prestep(x, y1, y2)
1452
1479
"""
1453
1480
steps = np .zeros ((1 + len (args ), max (2 * len (x ) - 1 , 0 )))
1454
1481
# In all `pts_to_*step` functions, only assign *once* using `x` and `args`,
@@ -1486,7 +1513,7 @@ def pts_to_poststep(x, *args):
1486
1513
1487
1514
Examples
1488
1515
--------
1489
- >> x_s, y1_s, y2_s = pts_to_poststep(x, y1, y2)
1516
+ >>> x_s, y1_s, y2_s = pts_to_poststep(x, y1, y2)
1490
1517
"""
1491
1518
steps = np .zeros ((1 + len (args ), max (2 * len (x ) - 1 , 0 )))
1492
1519
steps [0 , 0 ::2 ] = x
@@ -1522,7 +1549,7 @@ def pts_to_midstep(x, *args):
1522
1549
1523
1550
Examples
1524
1551
--------
1525
- >> x_s, y1_s, y2_s = pts_to_midstep(x, y1, y2)
1552
+ >>> x_s, y1_s, y2_s = pts_to_midstep(x, y1, y2)
1526
1553
"""
1527
1554
steps = np .zeros ((1 + len (args ), 2 * len (x )))
1528
1555
x = np .asanyarray (x )
@@ -1543,19 +1570,19 @@ def pts_to_midstep(x, *args):
1543
1570
1544
1571
def index_of (y ):
1545
1572
"""
1546
- A helper function to get the index of an input to plot
1547
- against if x values are not explicitly given.
1573
+ A helper function to create reasonable x values for the given *y*.
1574
+
1575
+ This is used for plotting (x, y) if x values are not explicitly given.
1548
1576
1549
- Tries to get ` y.index` (works if this is a pd .Series), if that
1550
- fails, return np.arange(y.shape[0]) .
1577
+ First try `` y.index`` (assuming *y* is a `pandas .Series` ), if that
1578
+ fails, use ``range(len(y))`` .
1551
1579
1552
1580
This will be extended in the future to deal with more types of
1553
1581
labeled data.
1554
1582
1555
1583
Parameters
1556
1584
----------
1557
1585
y : scalar or array-like
1558
- The proposed y-value
1559
1586
1560
1587
Returns
1561
1588
-------
@@ -1570,6 +1597,12 @@ def index_of(y):
1570
1597
1571
1598
1572
1599
def safe_first_element (obj ):
1600
+ """
1601
+ Return the first element in *obj*.
1602
+
1603
+ This is an type-independent way of obtaining the first element, supporting
1604
+ both index access and the iterator protocol.
1605
+ """
1573
1606
if isinstance (obj , collections .abc .Iterator ):
1574
1607
# needed to accept `array.flat` as input.
1575
1608
# np.flatiter reports as an instance of collections.Iterator
@@ -1586,27 +1619,33 @@ def safe_first_element(obj):
1586
1619
1587
1620
1588
1621
def sanitize_sequence (data ):
1589
- """Converts dictview object to list"""
1622
+ """
1623
+ Convert dictview objects to list. Other inputs are returned unchanged.
1624
+ """
1590
1625
return (list (data ) if isinstance (data , collections .abc .MappingView )
1591
1626
else data )
1592
1627
1593
1628
1594
1629
def normalize_kwargs (kw , alias_mapping = None , required = (), forbidden = (),
1595
1630
allowed = None ):
1596
- """Helper function to normalize kwarg inputs
1631
+ """
1632
+ Helper function to normalize kwarg inputs.
1597
1633
1598
1634
The order they are resolved are:
1599
1635
1600
- 1. aliasing
1601
- 2. required
1602
- 3. forbidden
1603
- 4. allowed
1636
+ 1. aliasing
1637
+ 2. required
1638
+ 3. forbidden
1639
+ 4. allowed
1604
1640
1605
1641
This order means that only the canonical names need appear in
1606
- ` allowed`, ` forbidden`, ` required`
1642
+ * allowed*, * forbidden*, * required*.
1607
1643
1608
1644
Parameters
1609
1645
----------
1646
+ kw : dict
1647
+ A dict of keyword arguments.
1648
+
1610
1649
alias_mapping : dict or Artist subclass or Artist instance, optional
1611
1650
A mapping between a canonical name to a list of
1612
1651
aliases, in order of precedence from lowest to highest.
@@ -1617,17 +1656,17 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
1617
1656
If an Artist subclass or instance is passed, use its properties alias
1618
1657
mapping.
1619
1658
1620
- required : iterable , optional
1621
- A tuple of fields that must be in kwargs .
1659
+ required : list of str , optional
1660
+ A list of keys that must be in *kws* .
1622
1661
1623
- forbidden : iterable , optional
1624
- A list of keys which may not be in kwargs
1662
+ forbidden : list of str , optional
1663
+ A list of keys which may not be in *kw*.
1625
1664
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`
1665
+ allowed : list of str , optional
1666
+ A list of allowed fields. If this not None, then raise if
1667
+ *kw* contains any keys not in the union of * required*
1668
+ and * allowed* . To allow only the required fields pass in
1669
+ an empty tuple ``allowed= ()``.
1631
1670
1632
1671
Raises
1633
1672
------
0 commit comments