Skip to main content

depictr (Python)

DOI CI docs PyPI Python versions License: MIT

Documentation and example gallery: https://pablobernabeu.github.io/depictr-py/

A unified, colourblind-safe toolkit for publication-ready statistical visualisation, built on plotnine. It is the Python sibling of the depictr R package.

Gallery

A grouped density (the default palette is the colourblind-safe Okabe-Ito set) and Kaplan-Meier survival curves with a log-rank test and a number-at-risk table, both from a single function call:

Grouped density of response times by priming condition, in the Okabe-Ito palette

Kaplan-Meier survival curves by treatment arm, with a log-rank test and a number-at-risk table

There is more in the example gallery. These two use a couple of extra options (a title, legend_inside) shown in the Getting started guide, while the short tour below keeps its calls minimal.

What it is for

Python already has an excellent plot for almost any statistical task, but they live in different packages with different defaults. A single figure set for a paper might draw on seaborn, scikit-learn, statsmodels, lifelines and ArviZ, each with its own look, its own API and its own colour scheme, and only one of those defaults to colourblind-safe colours. Making the set consistent and accessible then means repeating the same theming by hand on every plot.

depictr does that work once. It gives the whole workflow one theme, one colourblind-safe palette and one calling convention, and returns plotnine objects you can keep extending with +. Where a specialist package already computes a quantity well, depictr delegates to it and redraws the result under the shared theme, so you keep the trusted computation and gain a coherent, accessible figure.

Accessibility by default

The default palette is the Okabe-Ito set, and that choice is checked rather than asserted. The package ships a simulator of colour-vision deficiency based on the model of Machado, Oliveira and Fernandes (2009) and a CIE-Lab distance test that measures how far apart the palette's colours stay under each deficiency:

import depictr as dp

dp.palette_safety()
# {'min_delta_e': ..., 'by_condition': {'normal': ..., 'protan': ...,
#  'deutan': ..., 'tritan': ...}, 'worst_condition': ..., 'worst_pair': ...,
#  'safe': True, 'threshold': 5.0}

Installation

depictr is on PyPI:

pip install depictr            # core (plotnine, pandas, numpy, matplotlib, scipy)
pip install depictr[all]       # plus the optional computation back-ends

The classification, model and survival plots delegate to scikit-learn, statsmodels and lifelines respectively. Each is an optional dependency, so the core stays light and you install only what your plots need (depictr[classification], depictr[models], depictr[survival]).

A short tour

import depictr as dp

# Exploratory analysis
ld = dp.lexical_decision()
dp.explore_distribution(ld, "RT", group="condition", kind="both")

wb = dp.wellbeing_survey()
dp.correlation_heatmap(wb)
dp.missingness_map(wb)

# Model estimates: a fitted model OR a tidy data frame
import statsmodels.formula.api as smf
# Q() quotes "yield" because it is a Python keyword.
fit = smf.ols('Q("yield") ~ fertiliser + rainfall + soil_ph + treatment',
              dp.crop_yield()).fit()
dp.coefficient_plot(fit)

# Classification: computed by scikit-learn, themed by depictr
ct = dp.clinical_trial()
dp.roc_curve_plot(ct["adverse_event"], ct["biomarker"])

# Survival: Kaplan-Meier with a log-rank test, in one call
dp.survival_plot(ct["time"], ct["event"], group=ct["arm"])

Every function returns a plotnine object, so the usual grammar-of-graphics extensions apply:

from plotnine import labs

dp.roc_curve_plot(ct["adverse_event"], ct["biomarker"]) + labs(title="Adverse event")

The web app

A Streamlit app provides a gallery and a low-friction way to try the package: it loads one of the bundled datasets (or a CSV you upload), draws the chosen plot, shows the exact Python call that produced it, and offers a colourblind-vision toggle that re-renders the figure as each deficiency would be seen. The app lives in the repository rather than the wheel, so run it from a clone:

git clone https://github.com/pablobernabeu/depictr-py
cd depictr-py
pip install -e ".[app]"
streamlit run app/streamlit_app.py

Function families

Family Functions
Theme and palette theme_depictr, scale_colour_depictr, scale_fill_depictr, depictr_palette
Accessibility palette_safety, simulate_cvd
Exploratory analysis explore_distribution, explore_categorical, explore_bivariate, scatter_trend, correlation_heatmap, missingness_map, ecdf_plot, ridgeline_plot, dumbbell_plot, outlier_plot, group_comparison_plot, raincloud_plot, explore_pairs
Estimation and tables estimation_plot (single- or two-panel Gardner-Altman), summary_table
Model estimates coefficient_plot, tidy_estimates, effects_plot, interaction_plot, compare_models, random_effects_plot, posterior_plot, frequentist_bayesian_plot, power_curve_plot
Diagnostics qq_plot, influence_plot, vif_plot, binned_residual_plot, residual_diagnostics_plot, model_report
Classification roc_curve_plot, pr_curve_plot, confusion_matrix_plot, calibration_plot, gain_plot, lift_plot, threshold_plot
Multivariate pca_plot, scree_plot, cluster_plot, dendrogram_plot, silhouette_plot
Survival survival_plot (with an optional number-at-risk table)
Time series acf_plot, decompose_plot, seasonal_plot, timeseries_plot
Composition arrange_plots, save_plot

Status

This is an early release, but coverage is broad: the colourblind-safe theme, the accessibility check, and most of the R package's plotting functions across every family (EDA, estimation, model estimates, diagnostics, classification, multivariate, survival and time series) are in place and tested. Multi-panel composites are built on arrange_plots, which uses plotnine's native plot composition: the four-panel residual_diagnostics_plot, the model_report dashboard, the two-panel Gardner-Altman estimation_plot, the frequentist-over-Bayesian overlay, and the survival number-at-risk table.

A few known limitations remain. plotnine compositions have no figure-level title, so a grid carries its titles on each panel (the survival and estimation composites place the title on their top panel). survival_plot does not yet draw the confidence band or censor marks the R package draws; its conf_level argument is accepted for future use. And a handful of functions from the R package are not ported: optimizer_fixef_plot (there is no clean statsmodels equivalent of lme4::allFit), k_diagnostic, palette_preview, model_fit_table and ts_forecast.

Relationship to the R package

The two are siblings, not a shared codebase. The R package targets ggplot2 and CRAN; this one targets plotnine and PyPI. They share the design: one accessible theme across the whole workflow, model-or-data-frame input, and extensible plot objects.

Licence

MIT. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

depictr-0.2.2.tar.gz (241.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

depictr-0.2.2-py3-none-any.whl (70.8 kB view details)

Uploaded Python 3

File details

Details for the file depictr-0.2.2.tar.gz.

File metadata

  • Download URL: depictr-0.2.2.tar.gz
  • Upload date:
  • Size: 241.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for depictr-0.2.2.tar.gz
Algorithm Hash digest
SHA256 3b5dc22c55b78d009258e43b4fab270ca6d676f4913ec884c2c0754ee0a82a1f
MD5 f4ab6d4ae2b521b1f392c82736d854f7
BLAKE2b-256 9e6f0d1dfc78d74519a3098717b8845fe8ac4de8f245d58b5b806aae4d7c3c52

See more details on using hashes here.

Provenance

The following attestation bundles were made for depictr-0.2.2.tar.gz:

Publisher: publish.yml on pablobernabeu/depictr-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file depictr-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: depictr-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 70.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for depictr-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74ff6b21ee043b71aeaabd25f80b9640c253065fc6b490a3060000ba09120822
MD5 9de9a2b70700d7644e8a8348f85a3a05
BLAKE2b-256 d8404ae577e7a1c823386ca38e334f4c8d1b3ee8ae08ea15a4526d88a262d7a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for depictr-0.2.2-py3-none-any.whl:

Publisher: publish.yml on pablobernabeu/depictr-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 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