Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf8c647

Browse filesBrowse files
committed
cbook docs cleanup
1 parent fac4ad5 commit cf8c647
Copy full SHA for cf8c647

File tree

Expand file treeCollapse file tree

1 file changed

+106
-67
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+106
-67
lines changed

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+106-67Lines changed: 106 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,20 @@ def process(self, s, *args, **kwargs):
200200

201201
class silent_list(list):
202202
"""
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>
206217
"""
207218
def __init__(self, type, seq=None):
208219
self.type = type
@@ -226,7 +237,7 @@ def __setstate__(self, state):
226237
class IgnoredKeywordWarning(UserWarning):
227238
"""
228239
A class for issuing warnings about keyword arguments that will be ignored
229-
by matplotlib
240+
by Matplotlib.
230241
"""
231242
pass
232243

@@ -235,7 +246,7 @@ def local_over_kwdict(local_var, kwargs, *keys):
235246
"""
236247
Enforces the priority of a local variable over potentially conflicting
237248
argument(s) from a kwargs dict. The following possible output values are
238-
considered in order of priority:
249+
considered in order of priority::
239250
240251
local_var > kwargs[keys[0]] > ... > kwargs[keys[-1]]
241252
@@ -245,26 +256,26 @@ def local_over_kwdict(local_var, kwargs, *keys):
245256
246257
Parameters
247258
----------
248-
local_var : any object
249-
The local variable (highest priority)
259+
local_var : any object
260+
The local variable (highest priority).
250261
251-
kwargs : dict
252-
Dictionary of keyword arguments; modified in place
262+
kwargs : dict
263+
Dictionary of keyword arguments; modified in place.
253264
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.
257268
258269
Returns
259270
-------
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.
262273
263274
Raises
264275
------
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.
268279
269280
"""
270281
out = local_var
@@ -447,7 +458,7 @@ def _get_data_path(*args):
447458

448459
def flatten(seq, scalarp=is_scalar_or_string):
449460
"""
450-
Return a generator of flattened nested containers
461+
Return a generator of flattened nested containers.
451462
452463
For example:
453464
@@ -526,9 +537,12 @@ def dedent(s):
526537

527538
class maxdict(dict):
528539
"""
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.
532546
"""
533547
def __init__(self, maxsize):
534548
dict.__init__(self)
@@ -702,15 +716,18 @@ def safe_masked_invalid(x, copy=False):
702716

703717
def print_cycles(objects, outstream=sys.stdout, show_progress=False):
704718
"""
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*.
709720
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.
712723
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
714731
If True, print the number of objects reached as they are found.
715732
"""
716733
import gc
@@ -868,17 +885,18 @@ def simple_linear_interpolation(a, steps):
868885
"""
869886
Resample an array with ``steps - 1`` points between original point pairs.
870887
888+
Along each column of *a*, ``(steps - 1)`` points are introduced between
889+
each original values; the values are linearly interpolated.
890+
871891
Parameters
872892
----------
873893
a : array, shape (n, ...)
874894
steps : int
875895
876896
Returns
877897
-------
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, ...)``
882900
"""
883901
fps = a.reshape((len(a), -1))
884902
xp = np.arange(len(a)) * steps
@@ -1246,8 +1264,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
12461264

12471265
def contiguous_regions(mask):
12481266
"""
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.
12511269
"""
12521270
mask = np.asarray(mask, dtype=bool)
12531271

@@ -1271,8 +1289,12 @@ def contiguous_regions(mask):
12711289

12721290

12731291
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+
"""
12761298
s = str(s)
12771299
dollar_count = s.count(r'$') - s.count(r'\$')
12781300
even_dollars = (dollar_count > 0 and dollar_count % 2 == 0)
@@ -1333,10 +1355,14 @@ def _reshape_2D(X, name):
13331355
def violin_stats(X, method, points=100, quantiles=None):
13341356
"""
13351357
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.
13401366
13411367
Parameters
13421368
----------
@@ -1350,7 +1376,7 @@ def violin_stats(X, method, points=100, quantiles=None):
13501376
return a vector of the values of the KDE evaluated at the values
13511377
specified in coords.
13521378
1353-
points : scalar, default = 100
1379+
points : int, default = 100
13541380
Defines the number of points to evaluate each of the gaussian kernel
13551381
density estimates at.
13561382
@@ -1362,8 +1388,9 @@ def violin_stats(X, method, points=100, quantiles=None):
13621388
13631389
Returns
13641390
-------
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:
13671394
13681395
- coords: A list of scalars containing the coordinates this particular
13691396
kernel density estimate was evaluated at.
@@ -1448,7 +1475,7 @@ def pts_to_prestep(x, *args):
14481475
14491476
Examples
14501477
--------
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)
14521479
"""
14531480
steps = np.zeros((1 + len(args), max(2 * len(x) - 1, 0)))
14541481
# In all `pts_to_*step` functions, only assign *once* using `x` and `args`,
@@ -1486,7 +1513,7 @@ def pts_to_poststep(x, *args):
14861513
14871514
Examples
14881515
--------
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)
14901517
"""
14911518
steps = np.zeros((1 + len(args), max(2 * len(x) - 1, 0)))
14921519
steps[0, 0::2] = x
@@ -1522,7 +1549,7 @@ def pts_to_midstep(x, *args):
15221549
15231550
Examples
15241551
--------
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)
15261553
"""
15271554
steps = np.zeros((1 + len(args), 2 * len(x)))
15281555
x = np.asanyarray(x)
@@ -1543,19 +1570,19 @@ def pts_to_midstep(x, *args):
15431570

15441571
def index_of(y):
15451572
"""
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.
15481576
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))``.
15511579
15521580
This will be extended in the future to deal with more types of
15531581
labeled data.
15541582
15551583
Parameters
15561584
----------
15571585
y : scalar or array-like
1558-
The proposed y-value
15591586
15601587
Returns
15611588
-------
@@ -1570,6 +1597,12 @@ def index_of(y):
15701597

15711598

15721599
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+
"""
15731606
if isinstance(obj, collections.abc.Iterator):
15741607
# needed to accept `array.flat` as input.
15751608
# np.flatiter reports as an instance of collections.Iterator
@@ -1586,27 +1619,33 @@ def safe_first_element(obj):
15861619

15871620

15881621
def sanitize_sequence(data):
1589-
"""Converts dictview object to list"""
1622+
"""
1623+
Convert dictview objects to list. Other inputs are returned unchanged.
1624+
"""
15901625
return (list(data) if isinstance(data, collections.abc.MappingView)
15911626
else data)
15921627

15931628

15941629
def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
15951630
allowed=None):
1596-
"""Helper function to normalize kwarg inputs
1631+
"""
1632+
Helper function to normalize kwarg inputs.
15971633
15981634
The order they are resolved are:
15991635
1600-
1. aliasing
1601-
2. required
1602-
3. forbidden
1603-
4. allowed
1636+
1. aliasing
1637+
2. required
1638+
3. forbidden
1639+
4. allowed
16041640
16051641
This order means that only the canonical names need appear in
1606-
`allowed`, `forbidden`, `required`
1642+
*allowed*, *forbidden*, *required*.
16071643
16081644
Parameters
16091645
----------
1646+
kw : dict
1647+
A dict of keyword arguments.
1648+
16101649
alias_mapping : dict or Artist subclass or Artist instance, optional
16111650
A mapping between a canonical name to a list of
16121651
aliases, in order of precedence from lowest to highest.
@@ -1617,17 +1656,17 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
16171656
If an Artist subclass or instance is passed, use its properties alias
16181657
mapping.
16191658
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*.
16221661
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*.
16251664
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=()``.
16311670
16321671
Raises
16331672
------

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.