plastid.plotting.plotutils module

This module contains utility functions for plotting:

Helper function to check arguments of plotting functions. Retrieve figure and axes from axes. If axes is None, create figure and axes, and return those.
Split a matplotlib.axes.Axes into one or more panels, with tied x and y axes. Also hides overlapping tick labels
Remove pairs of values from two arrays of data if either element in the pair is nan or inf. Used to prepare data for histogram or violin plots; as even masked nan and inf values are not handled by these functions.
Evaluate a kernel density estimate over observed data in linear or log-transformed space (e.g. for making violin plots in log space, but having kernels appropriately scaled).
plastid.plotting.plotutils.clean_invalid(x, y, min_x=-inf, min_y=-inf, max_x=inf, max_y=inf)[source]

Remove corresponding values from x and y when one or both of those is nan or inf, and optionally truncate values to minima and maxima

x, y : numpy.ndarray or list

Pair arrays or lists of corresponding numbers

min_x, min_y, max_x, max_y : number, optional

If supplied, set values below min_x to min_x, values larger than max_x to max_x and so for min_y and max_y


A shortened version of x, excluding invalid values


A shortened version of y, excluding invalid values


Retrieve figure and axes from axes. If axes is None, both.

Used as a helper function for replotting atop existing axes, by functions defined in plastid.plotting.plots.

axes : matplotlib.axes.Axes or None

Axes in which to place plot. If None, a new figure is generated.


Parent figure of axes


Axes containing plot

plastid.plotting.plotutils.get_kde(data, log=False, base=2, points=100, bw_method='scott')[source]

Estimate a kernel density (kde) over data

data : numpy.ndarray

Data to build kde over

log : bool, optional

If True, data is log-transformed before the kde is estimated. Data are converted back to non-log space afterwards.

base : 2, 10, or numpy.e, optional

If log is True, this serves as the base of the log space. If log is False, this is ignored. (Default: 2)

points : int

Number of points over which to evaluate kde. (Default: 100)

bw_method : str

Bandwith estimation method. See documentation for scipy.stats.gaussian_kde. (Default: “scott”)


Points over which kde is evaluated (x-values), in non-log space


Value of kde (y-values), in non-log space

plastid.plotting.plotutils.split_axes(ax, top_height=0, left_width=0, right_width=0, bottom_height=0, main_ax_kwargs={}, other_ax_kwargs={})[source]

Split the spaces taken by one axes into one or more panes, setting the original axes invisible.

ax : matplotlib.axes.Axes

Axes to split

top_height, left_width, right_width, bottom_height : float, optional

If not None, a panel on the corresponding side of the ax will be created, using whatever fraction is specified (e.g. 0.1 to use 10% of total height).

main_ax_kwargs : dict

Dictionary of keyword arguments for central panes, passed to matplotlib.figure.Figure.add_axes()

other_ax_kwargs : dict

Dictionary of keyword arguments for peripheral panes, passed to matplotlib.figure.Figure.add_axes()


Dictionary of axes. ‘orig’ refers to ax. The central panel is ‘main’. Other panels will be mapped to ‘top’, ‘left’ et c, if they are created.