magni.utils.plotting module

Module providing utilities for control of plotting using matplotlib.

The module has a number of public attributes which provide settings for colormap cycles, linestyle cycles, and marker cycles that may be used in combination with matplotlib.

Routine listings

setup_matplotlib(settings={}, cmap=None)
Function that set the Magni default matplotlib configuration.
colour_collections : dict
Collections of colours that may be used in e.g., a matplotlib color_cycle / prop_cycle.
seq_cmaps : list
Names of colormaps optimized for sequential data.
div_cmaps : list
Names of colormaps optimized for diverging data.
linestyles : list
A subset of linestyles from matplotlib.lines
markers : list
A subset of markers from matplotlib.markers


Use the default Magni matplotlib settings.

>>> import magni
>>> magni.utils.plotting.setup_matplotlib()

Get the normalised ‘Blue’ colour brew from the psp colour map:

>>> magni.utils.plotting.colour_collections['psp']['Blue']
((0.1255, 0.502, 0.8745),)
class magni.utils.plotting._ColourCollection(brews)[source]

Bases: object

A container for colour maps.

A single colour is stored as an RGB 3-tuple of integers in the interval [0,255]. A set of related colours is termed a colour brew and is stored as a list of colours. A set of related colour brews is termed a colour collection and is stored as a dictionary. The dictionary key identifies the name of the colour collection whereas the value is the list of colour brews.

The default colour collections named “cb*” are colorblind safe, print friendly, and photocopy-able. They have been created using the online ColorBrewer 2.0 tool [1].

Parameters:brews (dict) – The dictionary of colour brews from which the colour collection is created.


Each colour brew is a list (or tuple) of length 3 lists (or tuples) of RGB values.


[1]M. Harrower and C. A. Brewer, “ An Online Tool for Selecting Colour Schemes for Maps”, The Cartographic Journal, vol. 40, pp. 27-37, 2003 (See also:

Return a single colour brew.

The returned colour brew is normalised in the sense of matplotlib normalised rgb values, i.e., colours are 3-tuples of floats in the interval [0, 1].

Parameters:name (str) – Name of the colour brew to return.
Returns:brew (tuple) – A colour brew list.
magni.utils.plotting.setup_matplotlib(settings={}, cmap=None)[source]

Adjust the configuration of matplotlib.

Sets the default configuration of matplotlib to optimize for producing high quality plots of the data produced by the functionality provided in the Magni.

  • settings (dict, optional) – A dictionary of custom matplotlibrc settings. See examples for details about the structure of the dictionary.
  • cmap (str or tuple, optional) – Colormap to be used by matplotlib (the default is None, which implices that the ‘coolwarm’ colormap is used). If a tuple is supplied it must be a (‘colormap_name’, matplotlib.colors.Colormap()) tuple.

UserWarning – If the supplied custom settings are invalid.


For example, set lines.linewidth=2 and lines.color=’r’.

>>> from magni.utils.plotting import setup_matplotlib
>>> custom_settings = {'lines': {'linewidth': 2, 'color': 'r'}}
>>> setup_matplotlib(custom_settings)