uchrom.pl

uchrom.pl.draw_domains(ax, domains, bins=None, *, level: int | None = None, min_size: int = 2, **kwargs)[source]

Outline domains as squares on the diagonal of a matrix drawn with imshow (one row per locus).

Parameters:
  • ax (matplotlib Axes)

  • domains (DataFrame or sequence of (first_row, end_row)) – A domain table with start / end in bp (TADs, DI domains, FISHnet domains of one trace), placed on the rows by bins; or row-index pairs (end exclusive), e.g. the domains of uchrom.strc.tad.call_domains_fishnet_trace().

  • bins (DataFrame or array, optional) – The loci of the matrix rows (e.g. distance_map(...).bins, or their starts). Required for a table. A row range of a larger map works: domains are clipped to it. With a chrom column of one chromosome, only the domains on it are drawn.

  • level (int, optional) – For hierarchical tables (a level column): the level to draw (default all rows).

  • min_size (int) – Leave out domains (after clipping) shorter than this many rows.

  • **kwargs – Passed to matplotlib.patches.Rectangle (edgecolor, lw, …; default white).

Return type:

list of Rectangle

uchrom.pl.draw_loops(ax, loops: DataFrame, bins, *, symmetric: bool = True, **kwargs)[source]

Circle loops on a matrix drawn with imshow (one row per locus).

Parameters:
  • ax (matplotlib Axes)

  • loops (DataFrame) – BEDPE-like loop table (start1, start2; chrom1 filters to the matrix chromosome).

  • bins (DataFrame or array) – The loci of the matrix rows (e.g. distance_map(...).bins, or their starts); an anchor is placed on the row whose locus starts at it.

  • symmetric (bool) – Circle both (i, j) and (j, i) (default) or only (row of start1, column of start2).

  • **kwargs – Passed to ax.plot (default open cyan circles).

Return type:

list of Line2D

uchrom.pl.plot_compartments(cd, keys: Sequence[str], *, chrom: str | None = None, names: Sequence[str] | None = None, fig=None)[source]

Compartment tracks along a chromosome: per call the score (A positive, red; B blue) and the A/B labels as a bar, all on the loci of cd.

Parameters:
  • cd (ChromData) – Holds the calls (cd.results[key]: per-bin tables with chrom, start, end, compartment and pc2 / pc1 / score, as uchrom.strc.comp.call_compartments_axes_pc() and uchrom.strc.comp.call_compartments_hic() store them). Each locus of cd.bins shows the call of the bin that holds its midpoint, so calls on different bins (imaging loci, Hi-C bins) line up.

  • keys (sequence of str) – The calls to show, top to bottom.

  • chrom (str, optional) – Default: the first chromosome of the first call.

  • names (sequence of str, optional) – Track labels (default the keys).

  • fig (Figure, optional)

Return type:

Figure

uchrom.pl.plot_contact_map(matrix: ndarray, bin_ids: Sequence | None = None, title: str | None = None, cmap: str = 'magma', ax=None)[source]

Heatmap of a (n_bins, n_bins) contact frequency matrix (values in [0, 1]).

uchrom.pl.plot_distance_matrix(matrix: ndarray, bin_ids: Sequence | None = None, title: str | None = None, cmap: str = 'viridis_r', ax=None)[source]

Heatmap of a (n_bins, n_bins) population-mean distance matrix.

uchrom.pl.plot_rg_histogram(rg_series, bins: int = 30, title: str | None = None, ax=None)[source]

Histogram of per-trace radii of gyration.

uchrom.pl.plot_spatial(cd, color: str | Series, *, key: str = 'default', regions: Sequence[str] | None = None, cells=None, physical: bool = False, ax=None, size: float | None = None, marker: str | None = None, cmap: str = 'viridis', vmin=None, vmax=None, robust: bool = True, center: float | None = None, title: str | None = None, colorbar: bool = True, panel_width: float = 3.2)[source]

Plot cells at their positions coloured by color.

Parameters:
  • cd – A ChromData with cell positions.

  • color – A cd.cells column, or a Series indexed by cell id.

  • key – The position set, a subset of cells, physical units (uchrom.spatial.cell_positions_table()).

  • cells – The position set, a subset of cells, physical units (uchrom.spatial.cell_positions_table()).

  • physical – The position set, a subset of cells, physical units (uchrom.spatial.cell_positions_table()).

  • regions – The regions to draw (default all); one panel each.

  • ax – One Axes per region (a single Axes for one region); default: a new figure.

  • size – Marker area and shape (default: squares filling a unit grid when positions are integers, dots else).

  • marker – Marker area and shape (default: squares filling a unit grid when positions are integers, dots else).

  • vmin – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

  • vmax – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

  • robust – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

  • center – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

Return type:

list of Axes

uchrom.pl.plot_structure_3d(cd_or_coords: Any, chrom: str | None = None, trace_id: int | str | None = None, colour: str | Sequence | ndarray = 'bin', cmap: str = 'viridis', tube_radius: float | None = None, spline_smoothing: bool = True, background: str = 'white', show_scalar_bar: bool | None = None, save_png: str | None = None, window_size: Tuple[int, int] = (900, 700), show: bool = True, plotter: Any = None, notebook: bool | None = None, jupyter_backend: str = 'static', bond_outlier_factor: float | None = None)[source]

Render a ChromData (or (n_bins, 3) coords) as a 3-D tube.

Parameters:
  • cd_or_coords (ChromData or ndarray (n_bins, 3)) – The structure to plot. A ChromData is sorted by (chrom, trace_id, start) and broken into contiguous sub-chains, each drawn as one tube so discontinuities are not bridged by fake edges.

  • chrom (str, optional) – Restrict to one chromosome.

  • trace_id (int or str, optional) – Restrict to one trace / allele.

  • colour ('bin' | 'chrom' | 'trace' | named colour | ndarray) – See the module docstring for the full colour contract.

  • cmap (str) – Matplotlib colour-map name used when colour is a gradient or a scalar array.

  • tube_radius (float, optional) – Radius of the rendered tube. If None, auto-picks 1.5 % of the bounding-box diagonal.

  • spline_smoothing (bool) – If True, interpolate each sub-chain with a Catmull-Rom-style spline before piping (nicer curvature at sharp bends).

  • background (str) – Colour of the plotter background.

  • show_scalar_bar (bool, optional) – Whether to render a colour-bar (default: auto based on colour mode).

  • save_png (str, optional) – If given, write a PNG to this path.

  • window_size ((int, int)) – Renderer resolution in pixels.

  • show (bool) – If True, call plotter.show() at the end (pops a window or renders inline in a notebook).

  • plotter (pyvista.Plotter, optional) – Add to an existing plotter instead of creating one.

  • notebook (bool, optional) – If None, auto-detect.

  • jupyter_backend (str) – Passed to plotter.show(jupyter_backend=...) — 'static' renders an inline image (safest for nbconvert / CI), 'trame' gives an interactive widget.

  • bond_outlier_factor (float, optional) – If set, any consecutive-bin bond longer than factor * median_bond is treated as a discontinuity and the chain is split at that point (rendered as two separate tubes with a visible gap). Default None keeps the chain continuous — use this when the algorithm produces a legitimate chain that just happens to have a scale mismatch between intra-TAD bonds and inter-TAD boundary bonds (the typical two-stage reconstruction case). Set to e.g. 50 to catch only pathologically long “bridges”.

Returns:

plotter – The plotter object (useful for adding annotations before calling show()). None if PyVista is not installed.

Return type:

pyvista.Plotter

Plotting helpers for population-level trace statistics.

uchrom.pl.trace_stats.plot_contact_map(matrix: ndarray, bin_ids: Sequence | None = None, title: str | None = None, cmap: str = 'magma', ax=None)[source]

Heatmap of a (n_bins, n_bins) contact frequency matrix (values in [0, 1]).

uchrom.pl.trace_stats.plot_distance_matrix(matrix: ndarray, bin_ids: Sequence | None = None, title: str | None = None, cmap: str = 'viridis_r', ax=None)[source]

Heatmap of a (n_bins, n_bins) population-mean distance matrix.

uchrom.pl.trace_stats.plot_rg_histogram(rg_series, bins: int = 30, title: str | None = None, ax=None)[source]

Histogram of per-trace radii of gyration.

3-D structure rendering

PyVista-based 3-D rendering of reconstructed chromatin structures.

Draws a ChromData (or raw coordinate arrays) as smooth tubes along the genomic chain — matching the look of the interactive web browser (uchrom-browser).

Works in notebooks (inline screenshot or interactive if pythreejs / trame backends are installed) and in scripts (save to PNG, or show an OS window). PyVista is imported lazily so importing uchrom.pl keeps its zero-cost path when the user only needs matplotlib helpers.

Colour options

colour accepts:

  • A matplotlib-style colour name or (r, g, b) tuple → whole chain painted uniformly.

  • 'bin' → gradient along bin index using cmap.

  • 'chrom' → one colour per chromosome (requires spots to carry chrom — automatically true for a ChromData).

  • 'trace' → one colour per trace (distinct alleles).

  • An (N,) numpy array of scalar values (e.g. epigenetic signal) → mapped through cmap.

uchrom.pl.structure_3d.plot_structure_3d(cd_or_coords: Any, chrom: str | None = None, trace_id: int | str | None = None, colour: str | Sequence | ndarray = 'bin', cmap: str = 'viridis', tube_radius: float | None = None, spline_smoothing: bool = True, background: str = 'white', show_scalar_bar: bool | None = None, save_png: str | None = None, window_size: Tuple[int, int] = (900, 700), show: bool = True, plotter: Any = None, notebook: bool | None = None, jupyter_backend: str = 'static', bond_outlier_factor: float | None = None)[source]

Render a ChromData (or (n_bins, 3) coords) as a 3-D tube.

Parameters:
  • cd_or_coords (ChromData or ndarray (n_bins, 3)) – The structure to plot. A ChromData is sorted by (chrom, trace_id, start) and broken into contiguous sub-chains, each drawn as one tube so discontinuities are not bridged by fake edges.

  • chrom (str, optional) – Restrict to one chromosome.

  • trace_id (int or str, optional) – Restrict to one trace / allele.

  • colour ('bin' | 'chrom' | 'trace' | named colour | ndarray) – See the module docstring for the full colour contract.

  • cmap (str) – Matplotlib colour-map name used when colour is a gradient or a scalar array.

  • tube_radius (float, optional) – Radius of the rendered tube. If None, auto-picks 1.5 % of the bounding-box diagonal.

  • spline_smoothing (bool) – If True, interpolate each sub-chain with a Catmull-Rom-style spline before piping (nicer curvature at sharp bends).

  • background (str) – Colour of the plotter background.

  • show_scalar_bar (bool, optional) – Whether to render a colour-bar (default: auto based on colour mode).

  • save_png (str, optional) – If given, write a PNG to this path.

  • window_size ((int, int)) – Renderer resolution in pixels.

  • show (bool) – If True, call plotter.show() at the end (pops a window or renders inline in a notebook).

  • plotter (pyvista.Plotter, optional) – Add to an existing plotter instead of creating one.

  • notebook (bool, optional) – If None, auto-detect.

  • jupyter_backend (str) – Passed to plotter.show(jupyter_backend=...) — 'static' renders an inline image (safest for nbconvert / CI), 'trame' gives an interactive widget.

  • bond_outlier_factor (float, optional) – If set, any consecutive-bin bond longer than factor * median_bond is treated as a discontinuity and the chain is split at that point (rendered as two separate tubes with a visible gap). Default None keeps the chain continuous — use this when the algorithm produces a legitimate chain that just happens to have a scale mismatch between intra-TAD bonds and inter-TAD boundary bonds (the typical two-stage reconstruction case). Set to e.g. 50 to catch only pathologically long “bridges”.

Returns:

plotter – The plotter object (useful for adding annotations before calling show()). None if PyVista is not installed.

Return type:

pyvista.Plotter

Cells in tissue

Cells in tissue space coloured by a per-cell value: one panel per region (section / field of view), squares on a barcode grid, dots otherwise; numeric values on a colour scale (robust limits by default), categories with a legend; the y axis points down when the position record says so (y_axis="down", image rows).

uchrom.pl.spatial.plot_spatial(cd, color: str | Series, *, key: str = 'default', regions: Sequence[str] | None = None, cells=None, physical: bool = False, ax=None, size: float | None = None, marker: str | None = None, cmap: str = 'viridis', vmin=None, vmax=None, robust: bool = True, center: float | None = None, title: str | None = None, colorbar: bool = True, panel_width: float = 3.2)[source]

Plot cells at their positions coloured by color.

Parameters:
  • cd – A ChromData with cell positions.

  • color – A cd.cells column, or a Series indexed by cell id.

  • key – The position set, a subset of cells, physical units (uchrom.spatial.cell_positions_table()).

  • cells – The position set, a subset of cells, physical units (uchrom.spatial.cell_positions_table()).

  • physical – The position set, a subset of cells, physical units (uchrom.spatial.cell_positions_table()).

  • regions – The regions to draw (default all); one panel each.

  • ax – One Axes per region (a single Axes for one region); default: a new figure.

  • size – Marker area and shape (default: squares filling a unit grid when positions are integers, dots else).

  • marker – Marker area and shape (default: squares filling a unit grid when positions are integers, dots else).

  • vmin – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

  • vmax – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

  • robust – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

  • center – Colour limits: given, else the 2nd / 98th percentiles (robust) or the range; center makes the scale symmetric around it (e.g. 0 for a centred score, with cmap="RdBu_r").

Return type:

list of Axes