mpl.cbook

A collection of utility functions and classes. Originally, many (but not all) were from the Python Cookbook – hence the name cbook.

This module is safe to import from anywhere within matplotlib; it imports matplotlib only at runtime.

Functions

align_iterators(func, *iterables) This generator takes a bunch of iterables that are ordered by func
allequal(seq) Return True if all elements of seq compare equal.
allpairs(x) return all possible pairs in sequence x
alltrue(seq) Return True if all elements of seq evaluate to True.
boxplot_stats(X[, whis, bootstrap, labels]) Returns list of dictionaries of staticists to be use to draw a series of box and whisker plots.
dedent(s) Remove excess indentation from docstring s.
delete_masked_points(*args) Find all masked and/or non-finite points in a set of arguments, and return the arguments with only the unmasked points remaining.
deprecated(since[, message, name, ...]) Decorator to mark a function as deprecated.
dict_delall(d, keys) delete all of the keys from the dict d
exception_to_str([s])
file_requires_unicode(x) Returns True if the given writable file-like object requires Unicode to be written to it.
finddir(o, match[, case]) return all attributes of o which match string in match. if case
flatten(seq[, scalarp]) Returns a generator of flattened nested containers
get_label(y, default_name)
get_recursive_filelist(args) Recurse all the files and dirs in args ignoring symbolic links
get_sample_data(fname[, asfileobj]) Return a sample data file.
get_split_ind(seq, N) seq is a list of words. Return the index into seq such that:
index_of(y) A helper function to get the index of an input to plot against if x values are not explicitly given.
is_math_text(s)
is_numlike(obj) return true if obj looks like a number
is_scalar(obj) return true if obj is not string like and is not iterable
is_scalar_or_string(val) Return whether the given object is a scalar or string like.
is_sequence_of_strings(obj) Returns true if obj is iterable and contains strings
is_string_like(obj) Return True if obj looks like a string
is_writable_file_like(obj) return true if obj looks like a file object with a write method
issubclass_safe(x, klass) return issubclass(x, klass) and return False on a TypeError
iterable(obj) return true if obj is iterable
listFiles(root[, patterns, recurse, ...]) Recursively list files
local_over_kwdict(local_var, kwargs, *keys) Enforces the priority of a local variable over potentially conflicting argument(s) from a kwargs dict.
mkdirs(newdir[, mode]) make directory newdir recursively, and set mode. Equivalent to
onetrue(seq) Return True if one element of seq is True.
pieces(seq[, num]) Break up the seq into num tuples
popall(seq) empty a list
print_cycles(objects[, outstream, show_progress]) objects
pts_to_midstep(x, *args) Covert continuous line to pre-steps
pts_to_poststep(x, *args) Covert continuous line to pre-steps
pts_to_prestep(x, *args) Covert continuous line to pre-steps
recursive_remove(path)
reduce((function, sequence[, initial]) -> value) Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value.
report_memory([i]) return the memory consumed by process
restrict_dict(d, keys) Return a dictionary that contains those keys that appear in both d and keys, with values from d.
reverse_dict(d) reverse the dictionary – may lose data if values are not unique!
safe_first_element(obj)
safe_masked_invalid(x)
safezip(*args) make sure args are equal len before zipping
simple_linear_interpolation(a, steps)
soundex(name[, len]) soundex module conforming to Odell-Russell algorithm
strip_math(s) remove latex formatting from mathtext
to_filehandle(fname[, flag, return_opened]) fname can be a filename or a file handle. Support for gzipped
unicode_safe(s)
unique(x) Return a list of unique elements of x
unmasked_index_ranges(mask[, compressed]) Find index ranges where mask is False.
violin_stats(X, method[, points]) Returns a list of dictionaries of data which can be used to draw a series of violin plots.
warn_deprecated(since[, message, name, ...]) Used to display deprecation warning in a standard way.
wrap(prefix, text, cols) wrap text with prefix at length cols

Classes

Bunch(**kwds) Often we want to just collect a bunch of stuff together, naming each item of the bunch; a dictionary’s OK for that, but a small do- nothing class is even handier, and prettier to use.
CallbackRegistry() Handle registering and disconnecting for a set of signals and
GetRealpathAndStat()
Grouper([init]) This class provides a lightweight way to group arbitrary objects together into disjoint sets when a full-blown graph data structure would be overkill.
MemoryMonitor([nmax])
Null(*args, **kwargs) Null objects always and reliably “do nothing.”
RingBuffer(size_max) class that implements a not-yet-full buffer
Sorter Sort by attribute or item
Stack([default]) Implement a stack where elements can be pushed on and you can move back and forth.
WeakKeyDictionary([dict]) Mapping class that references keys weakly.
Xlator All-in-one multiple-string-substitution class
converter([missing, missingval]) Base class for handling string -> python type with support for
maxdict(maxsize) A dictionary with a maximum size; this doesn’t override all the
ref alias of weakref
repeat for the specified number of times. If not specified, returns the object
silent_list(type[, seq]) override repr when returning a list of matplotlib artists to
todate([fmt, missing, missingval]) convert to a date or None
todatetime([fmt, missing, missingval]) convert to a datetime or None
tofloat([missing, missingval]) convert to a float or None
toint([missing, missingval]) convert to an int or None
tostr([missing, missingval]) convert to string or None
xrange xrange(start, stop[, step]) -> xrange object
zip alias of izip

Exceptions

IgnoredKeywordWarning A class for issuing warnings about keyword arguments that will be ignored
MatplotlibDeprecationWarning A class for issuing deprecation warnings for Matplotlib users.
mplDeprecation alias of MatplotlibDeprecationWarning