Skip to main content

pha-plots

Transcriptome visualisation utilities for PhatnaniLab.

CI PyPI version Python versions License: MIT

Installation

pip install pha-plots

Install with optional development dependencies:

pip install "pha-plots[dev]"

Usage

Cortical slices

draw_frontal_cortex and draw_motor_cortex each accept a list of per-layer numeric values (outermost layer first), a colormap, and optional normalization bounds. Frontal cortex uses 7 layers (I–VI and white matter); motor cortex uses 6 (no layer IV).

Summary of Frontal Cortex

import matplotlib.pyplot as plt
from pha_plots import draw_frontal_cortex, draw_motor_cortex

fig, (ax_f, ax_m) = plt.subplots(1, 2, figsize=(4, 3))

draw_frontal_cortex(
    ax_f,
    values=[0.1, 0.4, 0.8, 0.3, 0.6, 0.9, 0.5],  # 7 layers
    cmap="viridis",
    vmin=0, vmax=1,
)

draw_motor_cortex(
    ax_m,
    values=[0.2, 0.5, 0.7, 0.4, 0.8, 0.6],  # 6 layers
    cmap="viridis",
    vmin=0, vmax=1,
)

for ax in (ax_f, ax_m):
    ax.set_aspect("equal")
    ax.autoscale()
    ax.axis("off")

Pass is_sig (a list of booleans, one per layer) to mark significant layers with an annotation character:

draw_frontal_cortex(
    ax, values, "viridis", vmin=0, vmax=1,
    is_sig=[False, False, True, False, True, False, False],
    sig_annotation_char="*",
)

Spinal cord cross-section

draw_spinal_cord accepts a dictionary mapping anatomical region IDs to values. Any region absent from the dictionary is filled with nan_color (default 'lightgray').

Recognized region IDs:

ID Anatomy
Dors_Edge Dorsal edge
Lat_Edge Lateral edge (bilateral)
Vent_Edge Ventral edge
Dors_Med_White Dorsal median white matter
Med_Lat_White Medial–lateral white matter (bilateral)
Vent_Lat_White Ventral lateral white matter (bilateral)
Vent_Med_White Ventral median white matter
Dors_Horn Dorsal horn (bilateral)
Vent_Horn Ventral horn (bilateral)
Med_Grey Medial grey matter
Cent_Can Central canal

Summary of Spinal Cord

from pha_plots import draw_spinal_cord

fig, ax = plt.subplots(figsize=(3, 3))

draw_spinal_cord(
    ax,
    values={
        "Dors_Horn":      0.9,
        "Vent_Horn":      0.7,
        "Med_Grey":       0.4,
        "Dors_Med_White": 0.2,
        "Vent_Med_White": 0.3,
    },
    cmap="plasma",
    vmin=0, vmax=1,
)

ax.set_aspect("equal")
ax.autoscale()
ax.axis("off")

Significance annotations use the same is_sig / sig_annotation_char pattern, but is_sig is a dict[str, bool] keyed by region ID:

draw_spinal_cord(
    ax, values, "plasma", vmin=0, vmax=1,
    is_sig={"Dors_Horn": True, "Vent_Horn": False},
)

Colorbar

draw_colorbar creates a colorbar inset directly inside an existing axis at a bounding box given in data coordinates (x0, y0, width, height), so it moves and scales with the plot.

from pha_plots.utils import draw_colorbar

cbar, cax = draw_colorbar(
    ax,
    xycoords=(x_max + 0.02, y_min, 0.04, y_max - y_min),
    cmap="viridis",
    vmin=0, vmax=1,
    orientation="vertical",
    label="Expression (normalised)",
)

cbar is the matplotlib.colorbar.Colorbar instance; cax is the inset Axes on which it was drawn. Both are returned so tick positions, labels, and other properties can be adjusted after the call:

cbar.set_ticks([0, 0.5, 1])
cax.yaxis.set_tick_params(labelsize=6)

Combining all four

import matplotlib.pyplot as plt
from pha_plots import draw_frontal_cortex, draw_motor_cortex, draw_spinal_cord
from pha_plots.utils import draw_colorbar

CMAP, VMIN, VMAX = "viridis", 0.0, 1.0

fig, axes = plt.subplots(1, 3, figsize=(8, 3))

draw_frontal_cortex(
    axes[0],
    values=[0.1, 0.4, 0.8, 0.3, 0.6, 0.9, 0.5],
    cmap=CMAP, vmin=VMIN, vmax=VMAX,
)
draw_motor_cortex(
    axes[1],
    values=[0.2, 0.5, 0.7, 0.4, 0.8, 0.6],
    cmap=CMAP, vmin=VMIN, vmax=VMAX,
)
draw_spinal_cord(
    axes[2],
    values={"Dors_Horn": 0.9, "Vent_Horn": 0.7, "Med_Grey": 0.4},
    cmap=CMAP, vmin=VMIN, vmax=VMAX,
)

for ax in axes:
    ax.set_aspect("equal")
    ax.autoscale()
    ax.axis("off")

# Add a shared colorbar just outside the spinal cord panel.
x0, x1 = axes[2].get_xlim()
y0, y1 = axes[2].get_ylim()
draw_colorbar(
    axes[2],
    xycoords=(x1 + 0.02 * (x1 - x0), y0, 0.04 * (x1 - x0), y1 - y0),
    cmap=CMAP, vmin=VMIN, vmax=VMAX,
    label="Expression",
)

plt.tight_layout()
plt.savefig("expression_figure.pdf", bbox_inches="tight")

Development setup

git clone https://github.com/PhatnaniLab/phatnani_transcriptome_plots.git
cd phatnani_transcriptome_plots
pip install -e ".[dev]"
pytest

Releasing

  1. Create and push a git tag matching v* (e.g. v0.1.0).
  2. Draft a GitHub Release from that tag.
  3. The publish workflow builds the distribution, pushes to TestPyPI, then promotes to PyPI automatically.

Trusted publishing — configure an OIDC publisher for pha-plots on PyPI/TestPyPI (no API tokens needed). See the PyPA guide.

License

MIT — see LICENSE.

Metadata

Release files for pha-plots 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pha-plots 0.1.0
File Size Uploaded
pha_plots-0.1.0.tar.gz 333.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pha-plots 0.1.0
File Interpreter ABI Platform
pha_plots-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 352.0 kB

Release files / pha_plots-0.1.0.tar.gz

Download URL pha_plots-0.1.0.tar.gz
Size 333.6 kB
Tags Source
SHA-256 checksum
How to use checksums
22519d2570dbebb67fc5c09b5d4ae0c124dd281a594d9c9967ff307e6c02554b
BLAKE2b-256 checksum
How to use checksums
8af5186dc9c3f82e998a5d1e191a11fa27690381ed06006124468f2877975f1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 8, 2026.

Transparency log

Release files / pha_plots-0.1.0-py3-none-any.whl

Download URL pha_plots-0.1.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
335cb0fc9769a844a862524655d723a1d7748f5d9e81fc9a1e9e6dd93ada4d81
BLAKE2b-256 checksum
How to use checksums
7c4f6de59718c3d777d568cdcc06aa6c20a6ee9661da156c5c3c1c734273f207
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page