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

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 = ...)."
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.

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.1.0},
  doi = {10.5281/zenodo.23456212},
}

Licence

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

Metadata

Release files for hairline 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 hairline 0.1.0
File Size Uploaded Provenance Actions
hairline-0.1.0.tar.gz 591.8 kB Without provenance Details for hairline-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 955.4 kB

Release files / hairline-0.1.0.tar.gz

Download URL hairline-0.1.0.tar.gz
Size 591.8 kB
Tags Source
SHA-256 checksum
How to use checksums
42a4e01bddc8107129e946f2e1dad7c4b5997e32b24483ba247cbc7d220b2763
BLAKE2b-256 checksum
How to use checksums
7706b1ddd335afb100cdbfc64ed9fc7af1868e5159987e954e6e2e6a9d62948a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.0-py3-none-any.whl

Download URL hairline-0.1.0-py3-none-any.whl
Size 363.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57577c65d8abae728e1625e860c19fe6df333eb6d74c2363e9feb76b7c532206
BLAKE2b-256 checksum
How to use checksums
e1674a26e456f35b1394d0e125f779c9eb4c9880c78765e32f486afa7fd11ce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.0

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