Skip to main content

Lightweight Cohort Flow Diagrams built on Matplotlib.

Project description

pycohortflow logo

pycohortflow

Lightweight cohort flow diagrams built on Matplotlib.

Turn a plain Python list of cohort steps into a publication-ready vertical flow chart with a single function call. Colours, fonts, spacing, and box geometry are fully customisable via TOML configuration files.

Installation

pip install pycohortflow

Quick Start

from pycohortflow import plot_cohort_flow_diagram
import matplotlib.pyplot as plt

data = [
    {"heading": "Registered Patients", "N": 350,
     "description": "Total patients registered in database"},
    {"heading": "Screening", "N": 150,
     "exclusion_description": "Did not meet inclusion criteria"},
    {"heading": "Eligible", "N": 120,
     "exclusion_description": "Declined / Lost to follow-up"},
    {"heading": "Final Analysis", "N": 115,
     "exclusion_description": "Data incomplete"},
]

fig, ax = plot_cohort_flow_diagram(
    data,
    figure_title="Clinical Cohort Flow Diagram",
)
plt.show()

Built-in Styles

Two styles ship with the package:

White style preview Colorful style preview

# Clean white boxes (default)
fig, ax = plot_cohort_flow_diagram(data, style="white")

# Pastel gradient backgrounds
fig, ax = plot_cohort_flow_diagram(data, style="colorful")

# Transparent figure background (for slides / posters)
fig, ax = plot_cohort_flow_diagram(data, transparent=True)

Customisation

Create a TOML file with only the values you want to override:

[figure]
dpi = 300

[colors]
main_start = "#cce5ff"
main_end   = "#d4edda"

Then pass it when plotting:

fig, ax = plot_cohort_flow_diagram(data, style_config_path="my_style.toml")

See the full documentation for all available options.

Saving Figures

fig, ax = plot_cohort_flow_diagram(
    data,
    save_dir="output",
    img_name="flow_chart",
    save_format=["png", "svg", "pdf"],
)

Requirements

  • Python >= 3.9
  • Matplotlib >= 3.5

License

AGPL-3.0 license


Roadmap

  • python based PRISMA2020 style generation, if necessary

Project details


Download files

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

Source Distribution

pycohortflow-0.1.1.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

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

pycohortflow-0.1.1-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file pycohortflow-0.1.1.tar.gz.

File metadata

  • Download URL: pycohortflow-0.1.1.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for pycohortflow-0.1.1.tar.gz
Algorithm Hash digest
SHA256 13580d94fb9b066843e88c7acca2baef17925f6f0b60e86b37ecc4fe2192e146
MD5 049cc6e30ad23492cbffac858a9a86f9
BLAKE2b-256 6125665aa3407b19e9f9e3965c9a5ef3c1501905de08de5d9eb3ca613c0625f0

See more details on using hashes here.

File details

Details for the file pycohortflow-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pycohortflow-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for pycohortflow-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eee54b4d266790c2649b64c55f6f2298bd219c001f16744becb0f7be98148621
MD5 963b4a8f1941dc85721785b6b13cfd13
BLAKE2b-256 b2022edcc272e550a73886fc1a5b7d501fc23016d78bc45082c6220fc12529ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page