lib5c.plotters.extendable.base_extendable_heatmap module¶
Module for the BaseExtendableHeatmap class, which provides the basic functionality of the extendable heatmap plotter.
-
class
lib5c.plotters.extendable.base_extendable_heatmap.
BaseExtendableHeatmap
(array, grange_x, grange_y=None, colorscale=None, colormap='obs', norm=None)[source]¶ Bases:
lib5c.plotters.extendable.extendable_figure.ExtendableFigure
Minimal implementation of an ExtendableFigure organized around a contact frequency heatmap.
The heatmap is plotted using
plt.imshow()
using data from thearray
attribute, colored using the other attributes, and the resulting axis is accessible ath['root']
whereh
is the ExtendableHeatmap instance.New axes can be added to the margins of the heatmap by calling
add_margin_ax()
. The axis of the new axis that is parallel to the heatmap will have its limits set to match thegrange_x
orgrange_y
attributes. This allows plotting features on the margin axes using genomic coordinates instead of having to convert to pixel coordinates.The root heatmap axis is still kept in units of pixels. To make drawing on this axis easier, this class provides
transform_feature()
, which will transform a genomic feature dict into heatmap pixel units.-
array
¶ Array of values to plot in the heatmap. Must be square.
- Type
np.ndarray
-
grange_x
¶ The genomic range represented by the x-axis of this heatmap. The dict should have the form:
{ 'chrom': str, 'start': int, 'end': int }
- Type
dict
-
grange_y
¶ The genomic range represented by the y-axis of this heatmap. If None, the heatmap is assumed to be symmetric.
- Type
dict, optional
-
colorscale
¶ The (min, max) of the color range to plot the values in the array with.
- Type
tuple of float
-
colormap
¶ The colormap to use when drawing the heatmap. Strings will be passed to lib5c.plotters.colormaps.get_colormap(). If array contains strings, pass a dict mapping those strings to colors.
- Type
str or matplotlib colormap or dict of colors
-
norm
¶ Pass an instance of
matplotlib.colors.Normalize
to apply this normalization to the heatmap and colorbar.- Type
matplotlib.colors.Normalize, optional
-
add_colorbar
(loc='right', size='10%', pad=0.1, new_ax_name='colorbar')[source]¶ Adds a colorbar to the heatmap in a new axis.
- Parameters
loc ({'top', 'bottom', 'left', 'right'}) – Which side of the heatmap to add the new colorbar to.
size (str) – The size of the new axis as a percentage of the main heatmap width. Should be passed as a string ending in ‘%’.
pad (float) – The padding to use between the existing parts of the figure and the newly added axis.
new_ax_name (str) – A name for the new axis. The axis will be accessible as
h[new_ax_name]
whereh
is this ExtendableHeatmap instance.
- Returns
The newly added colorbar.
- Return type
pyplot colorbar
-
add_margin_ax
(loc='bottom', size='10%', pad=0.0, new_ax_name='new_h_axis', axis_limits=(0, 1))[source]¶ Adds a new axis to the margin of this ExtendableHeatmap.
- Parameters
loc ({'top', 'bottom', 'left', 'right'}) – Which side of the figure to add the new axis to.
size (str) – The size of the new axis as a percentage of the main heatmap width. Should be passed as a string ending in ‘%’.
pad (float) – The padding to use between the existing parts of the figure and the newly added axis.
new_ax_name (str) – A name for the new axis. The axis will be accessible as
h[new_ax_name]
whereh
is this ExtendableHeatmap instance.
- Returns
The newly added axis.
- Return type
pyplot axis
-
transform_coord
(coord, axis='x')[source]¶ Convenience function for transforming genomic coordinates to heatmap pixel coordinates along a specified axis.
- Parameters
coord (int) – The genomic coordinate in base pairs.
axis ({'x', 'y'}) – The axis to convert the coordinate for.
- Returns
The
coord
expressed in heatmap pixel coordinates along the requested axis.- Return type
float
-
transform_feature
(feature, axis='x')[source]¶ Uses
transform_coord()
to transform an entire genomic feature dict to heatmap pixel coordinates.- Parameters
feature (dict) – Represents a genomic feature. Should have ‘chrom’, ‘start’, and ‘end’ keys. The values for ‘start’ and ‘end’ should be in base pair units.
axis ({'x', 'y'}) – The axis to convert the feature for.
- Returns
Will have keys ‘chrom’, ‘start’, and ‘end’, but the values for ‘start’ and ‘end’ will now be in units of heatmap pixels along the specified axis.
- Return type
dict
-