Skip to main content

bioviz-kit

Framework-agnostic visualization library for publication-ready clinical and biological data plots.

License: MIT Python 3.11+ Documentation

Features

  • Publication-ready styling – Clean, professional visualizations out of the box
  • Framework-agnostic – Works with any data pipeline or analysis framework
  • Pydantic configurations – Type-safe, validated configuration objects
  • Clinical & bioinformatics focused – Specialized plot types for common analyses:
    • Kaplan-Meier survival curves with risk tables
    • Volcano plots for differential expression/enrichment
    • Oncoplots (mutation landscapes)
    • Forest plots for hazard ratios
    • Waterfall plots for tumor response
    • Grouped bar charts with confidence intervals
    • Distribution plots (histogram + boxplot)
    • Styled tables

Installation

Install from PyPI:

pip install bioviz-kit

Or using uv to install into an environment:

uv pip install bioviz-kit

Or add it to a uv project:

uv add bioviz-kit

Install all optional plot backends when you want every plot family available:

pip install "bioviz-kit[all]"
uv pip install "bioviz-kit[all]"
uv add "bioviz-kit[all]"

Or install in development mode:

git clone https://github.com/vic-cheung/bioviz-kit.git
cd bioviz-kit
pip install -e .

Or using uv in editable/development mode:

uv pip install -e .

Or add a local editable checkout to another uv project:

uv add --editable ../bioviz-kit

Requirements

  • Python 3.11+
  • pandas
  • matplotlib
  • numpy
  • pydantic
  • scipy
  • optional extras: km, volcano, line, grouped, grouped-bar, or all

Quick Start

Kaplan-Meier Survival Plots

import pandas as pd
from bioviz.configs import KMPlotConfig
from bioviz.plots import KMPlotter

# Your survival data
df = pd.DataFrame({
    "time": [5, 10, 15, 8, 12, 20, 6, 14],
    "event": [1, 0, 1, 1, 0, 1, 1, 0],
    "arm": ["Treatment", "Treatment", "Treatment", "Treatment",
            "Control", "Control", "Control", "Control"],
})

# Configure the plot
config = KMPlotConfig(
    time_col="time",
    event_col="event",
    group_col="arm",
    title="Overall Survival by Treatment Arm",
    xlabel="Time (months)",
    ylabel="Survival Probability",
    show_risktable=True,
    show_pvalue=True,
    color_dict={"Treatment": "#009E73", "Control": "#D55E00"},
)

# Generate the plot
plotter = KMPlotter(df, config)
fig, ax, pval = plotter.plot(output_path="km_plot.pdf")
print(f"Log-rank p-value: {pval:.4f}")

Volcano Plots

from bioviz.configs import VolcanoConfig
from bioviz.plots import VolcanoPlotter

# Differential expression results
df = pd.DataFrame({
    "gene": ["TP53", "KRAS", "EGFR", "BRCA1", "MYC"],
    "log2fc": [2.5, -1.8, 0.3, 3.1, -2.2],
    "pvalue": [0.001, 0.01, 0.5, 0.0001, 0.005],
})

config = VolcanoConfig(
    x_col="log2fc",
    y_col="pvalue",
    label_col="gene",
    title="Differential Expression Analysis",
    y_col_thresh=0.05,
    abs_x_thresh=1.5,
)

plotter = VolcanoPlotter(df, config)
fig, ax = plotter.plot()
fig.savefig("volcano.pdf", bbox_inches="tight")

Oncoplots

import pandas as pd

from bioviz.configs import OncoplotConfig
from bioviz.plots import OncoPlotter

# Mutation data (long format)
df = pd.DataFrame({
    "sample": ["S1", "S1", "S2", "S2", "S3"],
    "gene": ["TP53", "KRAS", "TP53", "EGFR", "KRAS"],
    "variant_class": ["Missense", "Missense", "Nonsense", "Amplification", "Missense"],
})

config = OncoplotConfig(
    x_col="sample",
    y_col="gene",
    value_col="variant_class",
    fig_title="Mutation Landscape",
    row_values_color_dict={
        "Missense": "#1f77b4",
        "Nonsense": "#2ca02c",
        "Amplification": "#ff7f0e",
    },
)

fig = OncoPlotter(df, config).plot()
fig.savefig("oncoplot.pdf", bbox_inches="tight")

See the prevalence raster guide for cohort prevalence, event columns, and nested subtype bands.

Forest Plots

from bioviz.configs import ForestPlotConfig
from bioviz.plots import ForestPlotter

# Hazard ratio data
df = pd.DataFrame({
    "comparator": ["Age >= 65", "Male", "Stage III-IV", "ECOG 1"],
    "reference": ["Age < 65", "Female", "Stage I-II", "ECOG 0"],
    "hr": [1.45, 0.92, 2.10, 1.68],
    "ci_lower": [1.10, 0.72, 1.65, 1.25],
    "ci_upper": [1.91, 1.18, 2.67, 2.26],
    "p_value": [0.008, 0.52, 0.001, 0.001],
})

config = ForestPlotConfig(
    title="Multivariate Cox Regression",
    xlabel="Hazard Ratio (95% CI)",
)

plotter = ForestPlotter(df, config)
fig, ax = plotter.plot()
fig.savefig("forest.pdf", bbox_inches="tight")

Grouped Bar Charts with CIs

from bioviz.configs import GroupedBarConfig
from bioviz.plots import GroupedBarPlotter

# Create from proportions (computes Clopper-Pearson CIs automatically)
config = GroupedBarConfig(
    title="Response Rates by Treatment",
    xlabel="Response Rate (%)",
    orientation="horizontal",
    ci_method="clopper-pearson",
)

plotter = GroupedBarPlotter.from_proportions(
    category_list=["CR", "PR", "SD", "PD"],
    group_configs=[
        {"name": "Treatment", "k": {"CR": 15, "PR": 25, "SD": 30, "PD": 10}, "n": 80},
        {"name": "Control", "k": {"CR": 5, "PR": 15, "SD": 35, "PD": 25}, "n": 80},
    ],
    config=config,
)
fig, ax = plotter.plot()

Architecture

bioviz-kit follows a consistent pattern across all plot types:

bioviz/
├── configs/           # Pydantic configuration classes
│   ├── km_cfg.py      # KMPlotConfig
│   ├── volcano_cfg.py # VolcanoConfig
│   └── ...
├── plots/             # Plotter classes
│   ├── km.py          # KMPlotter
│   ├── volcano.py     # VolcanoPlotter
│   └── ...
└── utils/             # Shared utilities

Each plot type has:

  1. A Config class (e.g., KMPlotConfig) - Pydantic model with validated fields
  2. A Plotter class (e.g., KMPlotter) - Takes data + config, produces matplotlib figure

Configuration Philosophy

All configurations use Pydantic models with:

  • Type hints for IDE autocompletion
  • Validation to catch errors early
  • Defaults that produce publication-ready output
  • Documentation via field descriptions

Font sizes default to None to inherit from matplotlib's rcParams, making it easy to apply global themes:

import matplotlib.pyplot as plt

# Set global style
plt.rcParams.update({
    "font.size": 12,
    "axes.labelsize": 14,
    "axes.titlesize": 16,
})

# Now all bioviz plots will use these sizes by default

Examples

See the examples/ directory for complete, runnable examples:

  • minimal_bioviz_smoke.py - Line plots, oncoplots, tables
  • oncoplot_example.py - Detailed oncoplot customization
  • volcano_smoke.py - Volcano plot variations
  • distribution_examples.py - Histogram + boxplot combinations
  • km_survival_example.py - Kaplan-Meier survival analysis

Documentation

Full documentation is available at bioviz-kit.readthedocs.io.

License

bioviz-kit is released under the MIT License (c) 2025 Victoria Cheung.

Acknowledgments

This package was spun out of internal tooling developed at Revolution Medicines. Many thanks to the team there for allowing the code to be open sourced.

Metadata

Release files for bioviz-kit 0.4.3

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

Source distribution (sdist)

Source distribution for bioviz-kit 0.4.3
File Size Uploaded Provenance Actions
bioviz_kit-0.4.3.tar.gz 157.6 kB Without provenance Details for bioviz_kit-0.4.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bioviz-kit 0.4.3
File Interpreter ABI Platform Actions
bioviz_kit-0.4.3-py3-none-any.whl Python 3 none any Details for bioviz_kit-0.4.3-py3-none-any.whl

Total release size: 314.6 kB

Release files / bioviz_kit-0.4.3.tar.gz

Download URL bioviz_kit-0.4.3.tar.gz
Size 157.6 kB
Tags Source
SHA-256 checksum
How to use checksums
eb14e1072c7f7d185da02a62f88fb00d6de13d2cb48f13fda3dc3f9adbbf8a1e
BLAKE2b-256 checksum
How to use checksums
749ae8986c5bfb84579d5c0181405bb2cc7177821ff8a37c8eebdb535310adc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / bioviz_kit-0.4.3-py3-none-any.whl

Download URL bioviz_kit-0.4.3-py3-none-any.whl
Size 157.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40bc5f340d5ec3bf008e3ccb67e5c68206c86dc5a4eb22bc38ffd1743ac346f5
BLAKE2b-256 checksum
How to use checksums
604f769019b9aad89165f2e68109953ca937978f496db760df8be505008ad950
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Security for bioviz-kit 0.4.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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