lakeview.plot
lakeview.plot#
- lakeview.plot.get_cmap_colors(cmap_name, format_='hex')#
Get all colors for a given matplotlib palette.
Adapted from https://gist.github.com/jdbcode/33d37999f950a36b43e058d15280b536.
>>> get_cmap_colors("Set2") ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494', '#b3b3b3']
- lakeview.plot.get_random_colors(n, *, seed=0, cmap='hsv')#
Returns
n
random colors selected uniformly fromcmap
.>>> get_random_colors(3) [(0.0, 0.22463448382566054, 1.0, 1.0), (0.4018366371307548, 1.0, 0.0, 1.0), (1.0, 0.2316178786767022, 0.0, 1.0)]
- lakeview.plot.draw_rigid_polygon(ax, shape, position, position_transform, **kw)#
Draw a polygon patch with shape defined in inches and position defined in data, Axes or physical units.
- Parameters
ax (matplotlib.axes._axes.Axes) –
position_transform (matplotlib.transforms.Transform) –
- lakeview.plot.get_ax_size(ax)#
Return the size of a given Axes in inches.
>>> fig, ax = plt.subplots(figsize=(8, 6)) >>> get_ax_size(ax) (6.2, 4.62)
- Parameters
ax (matplotlib.axes._axes.Axes) –
- lakeview.plot.scientific_notation(x, significant_figures=3, *, quote='$')#
Returns scientific notation in Matplotlib mathtext format.
>>> scientific_notation(0.000000013923, 4) '$1.392\\times 10^{-8}$'
- class lakeview.plot.PrunedMaxNLocator#
Bases:
matplotlib.ticker.MaxNLocator
A Matplotlib tick locator that prunes ticks near the edge of the plot.
- __init__(nbins=4, prune=(0.05, 0.05))#
- Parameters
nbins (int) – Maximum number of intervals; one less than max number of ticks.
prune (tuple[float, float]) – A two-element
tuple
(prune_lower, prune_upper). Ticks outside the interval [vmin + prune_lower × (vmax - vmin), vmax - self._prune_upper × (vmax - vmin)] will be pruned. SeePrunedMaxNLocator.tick_values()
.
- tick_values(vmin, vmax)#
Return the values of the located ticks given vmin and vmax.
Note
To get tick locations with the vmin and vmax values defined automatically for the associated
axis
simply call the Locator instance:>>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
- class lakeview.plot.BasePairFormatter#
Bases:
matplotlib.ticker.FuncFormatter
A Matplotlib tick formatter for common base pair units (bp, kb, Mb, Gb, Tb).
>>> formatter = BasePairFormatter('kb') >>> formatter(24310) '24.310 kb' >>> formatter = BasePairFormatter('Mb', 2, show_suffix=False) >>> formatter(844_293_192) '844.29'
- __init__(unit, decimals=None, *, show_suffix=True)#
- classmethod from_limits(limits, *, show_suffix=True)#
Automatically select reasonable unit and decimals based on axes limits.
>>> fig, ax = plt.subplots() >>> ax.set_xlim(3200000, 5840000) (3200000.0, 5840000.0) >>> formatter = BasePairFormatter.from_limits(ax.get_xlim()) >>> formatter BasePairFormatter(unit='Mb', decimals=1, show_suffix=True) >>> ax.xaxis.set_major_formatter(formatter)