Skip to main content

hairline

Clean, predictable figures for medical and data science. One frame for titles, legends, panels and captions, one type scale, colour-vision checked palettes, and print-ready files. The R package of the same name draws the same figures from the same design tokens, so a Python figure and an R figure in one manuscript match.

pip install hairline

The development version, with changes not yet released (see the changelog), installs from GitHub: pip install "hairline @ git+https://github.com/schradern/hairline#subdirectory=python".

Python 3.11 or later, matplotlib 3.11 or later: from 3.11 matplotlib kerns text as R does, so both packages place every label alike. The bundled font, Hairline Sans, needs no installation.

ICU bed occupancy in small multiples, drawn with hairline

From data to a result

Most studies need the same few results: a cohort description, a comparison between groups, effects, events over time. study() takes a data frame once, with the role of each column, checks the data, and returns each result as a figure, a table, the key values and a sentence for the text.

import numpy as np
import pandas as pd
import hairline as hl

rng = np.random.default_rng(1)
cohort = pd.DataFrame({
    "arm": np.repeat(["Standard care", "Early mobilisation"], 40),
    "age": rng.normal(64, 12, 80).round(),
    "sex": rng.choice(["Female", "Male"], 80),
    "months": rng.exponential(20, 80).round(1),
    "died": rng.binomial(1, 0.4, 80),
})
study = hl.study(cohort, group="arm", time="months", event="died",
                 units={"age": "years", "months": "months"})

table_one = study.describe()     # Table 1: median (IQR) and n (%) per group
table_one.table                  # a data frame
age = study.compare("age")       # spread rows per group, Wilcoxon rank-sum
age.text                         # "Age (years), median (IQR): ... (Wilcoxon rank-sum, p = ...)."
age.numbers["test"]["p"]         # the unrounded p the text formats
survival = study.survival()      # Kaplan–Meier with numbers at risk and the log-rank test
hl.save(survival.figure, "survival")              # survival.pdf and survival.png

Printing a study lists its checks: missing values, duplicate ids, categories that differ only in case, small groups, numeric columns without a unit. Errors stop the analysis; warnings name the fix. With id=, describe(), compare() and distribution() refuse a variable with more than one row per id, so repeated measurements are not counted as separate patients.

Charts

Each chart is one call with the data and its column names, and returns a figure in the hairline frame: bars, scatter, timeseries, spread, raincloud, ridgeline, kaplan_meier, forest, dotplot, funnel, correlation, donut, partition, sankey, chord, arcs, venn, prisma and risk_of_bias.

admissions = pd.DataFrame({"diagnosis": ["Sepsis", "Sepsis", "Trauma", "Cardiac", "Cardiac"],
                           "sex": ["Female", "Male", "Male", "Female", "Male"]})
figure = hl.bars(admissions, "diagnosis", by="sex", subtitle="Admissions, 2025")
hl.save(figure, "admissions", formats=["pdf", "png", "svg", "html"])

For anything else, hl.figure() gives the same frame around your own matplotlib axes:

figure = hl.figure("Lactate falls after admission", subtitle="Mean per day", size="single")
figure.ax.plot([0, 1, 2, 3], [4.1, 3.2, 2.6, 2.2], label="All patients")
figure.y_title("mmol/l")
hl.save(figure, "lactate")

Colours

Groups take a palette's colours in order, so two groups always get the same two colours and a group keeps its colour in every chart. hl.palettes() lists the six palettes, the purpose sets (two groups, greyscale print, risk of bias) and the ramps for amounts; hl.swatches() draws them; hl.use(palette="calm") changes the default; hl.use(colors={"Unit B": "#e79d01"}) pins a colour to a name; hl.colormap("blues") gives a ramp to your own matplotlib plots. help(hairline.palettes) has the details.

Files

save() writes PDF (fonts embedded), PNG and TIFF (600 dpi by default), SVG (text kept as text) and self-contained interactive HTML with tooltips. Files carry the figure's title and subtitle as their description, and no timestamps: the same figure gives the same bytes again.

Design

  • hl.use(brand="_brand.yml") applies an institution's colours, fonts and sizes from a brand.yml file; several files layer from institution to document.
  • hl.use(colors={"Unit B": "#e79d01"}) pins a colour to a name across every chart.
  • Palettes are checked for colour-vision separation and contrast; hl.check_palette() reports the numbers.
  • hl.use(scheme="dark", accent="#0b6e4f") draws on a dark surface with an accent for single series.

More figures, Python and R side by side, and the colour guide: https://github.com/schradern/hairline.

The same figure in Python and R

Author

Nikolas Schrader (hi@nikolasschrader.com), ORCID 0009-0001-4616-3804.

How to cite

If hairline helped you make the figures in your work, please cite it; hl.citation() gives the reference and hl.citation("bibtex") this entry:

@Manual{schrader2026hairline,
  title = {hairline: Clean, Predictable Figures for Medical and Data Science},
  author = {Nikolas Schrader},
  year = {2026},
  note = {Python package version 0.2.1},
  doi = {10.5281/zenodo.23456211},
}

Licence

MIT. The bundled Hairline Sans font is a modified Public Sans (SIL Open Font License 1.1).

Metadata

Release files for hairline 0.2.1

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

Source distribution (sdist)

Source distribution for hairline 0.2.1
File Size Uploaded Provenance Actions
hairline-0.2.1.tar.gz 753.3 kB Without provenance Details for hairline-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hairline 0.2.1
File Interpreter ABI Platform Actions
hairline-0.2.1-py3-none-any.whl Python 3 none any Details for hairline-0.2.1-py3-none-any.whl

Total release size: 1.2 MB

Release files / hairline-0.2.1.tar.gz

Download URL hairline-0.2.1.tar.gz
Size 753.3 kB
Tags Source
SHA-256 checksum
How to use checksums
541ce9b63900dc3a969096f619c384359f3fa434c64fdb6e3865a6ec660abd3b
BLAKE2b-256 checksum
How to use checksums
3eec2538e4c1ea7ae9385cdb72a931881cb2950f79281e9a17aafe251e01c158
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hairline-0.2.1-py3-none-any.whl

Download URL hairline-0.2.1-py3-none-any.whl
Size 403.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d748ed76fecd328b4356e1a432f98308e6f9a229892f5c44e2b33edbd8ef985
BLAKE2b-256 checksum
How to use checksums
a396ec504bbfe09f9e2710e451f48dec1d26563723395927b08d1ab2f77c582b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for hairline 0.2.1

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