plastid.plotting.plotutils module

This module contains utility functions for plotting:

get_fig_axes()

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_axes()

Split a matplotlib.axes.Axes into one or more panels, with tied x and y axes. Also hides overlapping tick labels

clean_invalid()

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.

get_kde()

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

Parameters
x, ynumpy.ndarray or list

Pair arrays or lists of corresponding numbers

min_x, min_y, max_x, max_ynumber, 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

Returns
numpy.ndarray

A shortened version of x, excluding invalid values

numpy.ndarray

A shortened version of y, excluding invalid values

plastid.plotting.plotutils.get_fig_axes(axes=None)[source]

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.

Parameters
axesmatplotlib.axes.Axes or None

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

Returns
matplotlib.figure.Figure

Parent figure of axes

matplotlib.axes.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

Parameters
datanumpy.ndarray

Data to build kde over

logbool, optional

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

base2, 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)

pointsint

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

bw_methodstr

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

Returns
numpy.ndarray

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

numpy.ndarray

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.

Parameters
axmatplotlib.axes.Axes

Axes to split

top_height, left_width, right_width, bottom_heightfloat, 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_kwargsdict

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

other_ax_kwargsdict

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

Returns
dict

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.