Skip to main content

sciglyph

PyPI test python license

Publication-quality scientific illustration in pure matplotlib — no BioRender, no Illustrator.

Overview figures and architecture diagrams are usually drawn by hand in a subscription tool. That makes them pretty, but also unreproducible: you cannot diff them, you cannot regenerate them when the numbers change, and you cannot put them under version control.

sciglyph gives you the primitives to draw the same figures as code.

Both figures above are generated by the scripts in examples/ — nothing was touched by hand. The content is synthetic; swap in your own numbers and the layout carries over.


Why

subscription tools sciglyph
Reproducible ✗ manual pixel-pushing ✓ a script
Version control ✗ binary blobs ✓ diffable source
Data-driven ✗ retype every number ✓ read straight from your results
Vector output ~ depends on export ✓ PDF/SVG with editable text
Cost subscription free, MIT

Install

pip install sciglyph

Only matplotlib and numpy. Nothing else.

Quick start

import matplotlib.pyplot as plt
from sciglyph import bio, set_canvas, report, RC

plt.rcParams.update(RC)
fig = plt.figure(figsize=(7.2, 3.0), dpi=300)
ax = fig.add_axes([0, 0, 1, 1]); ax.set_xlim(0, 1); ax.set_ylim(0, 1); ax.axis("off")
set_canvas(fig)                      # required on non-square canvases

bio.person(ax, .08, .55, s=.30)
bio.dna(ax, .25, .55, w=.05, h=.45, n=2)
bio.cell(ax, .42, .55, r=.06, seed=1)
bio.seq_logo(ax, .60, .40, [("A", .6), ("C", .9), ("G", .4), ("T", .7)], w=.03)

report(fig, ax)                      # catch text collisions before saving
fig.savefig("figure.pdf", bbox_inches="tight")

That block is runnable as it stands — it saves figure.pdf and prints the layout report on the way.

The two full examples behind the images above live in the repository rather than the wheel, so they need a clone:

git clone https://github.com/GuoCheng24/sciglyph && cd sciglyph
python examples/overview_figure.py    # -> gallery/overview_figure.png
python examples/architecture.py       # -> gallery/architecture.png

CONSORT flows, with the arithmetic checked

Every trial and most cohort papers need one, and journals require it for randomised trials. R has three packages for it; Python has had none, and the standing advice was to draw the boxes yourself in matplotlib.

from sciglyph import consort

fig, problems = consort.figure(
    spine=[("Assessed for eligibility", 1327),
           ("Enrolled", 915),
           ("Allocated to treatment", 458),
           ("Included in the primary analysis", 441)],
    excluded=[[("Did not meet inclusion criteria", 289),
               ("Declined to participate", 78),
               ("Other reasons", 45)],
              [("Allocated to the comparator arm", 457)],
              [("Lost to follow-up", 11), ("Withdrew consent", 6)]],
)
fig.savefig("consort.pdf", bbox_inches="tight")

The reason to draw one in code is that the numbers move: you re-clean the data, forty patients leave the eligible set, and the figure goes stale — silently, because nobody re-adds the boxes by hand.

So it does the thing a drawing tool can do that a drawing surface cannot. It checks that the counts reconcile, and refuses to draw a flow that does not:

the flow does not reconcile — 1 step(s) do not add up:
  step 1  'Assessed for eligibility' (1327) -> 'Enrolled' (900), excluded 367: unaccounted for 60
Fix the counts, or pass strict=False to draw it anyway.

Reviewers check that addition. Failing here is cheaper than failing there.

Every glyph at a glance

The catalogue itself is drawn by the library — docs/glyph_sheet_figure.py regenerates it, and a glyph that breaks shows up as a broken cell rather than a silently stale image.

What's included

sciglyph.bio — glyphs for Nature/Science-style overview figures: person (cohorts) · dna · cell · lipid · metabolite · nucleosome_chain · umap_layer (the stacked atlas look) · seq_logo (information-scaled letters, no logomaker needed) · stacked_planes · rbox · arr

sciglyph.arch — glyphs for architecture diagrams: cuboid / feature_stack (3-D feature blocks) · trapezoid (encoders) · module_stack (Conv|BN|ReLU bars) · dashed_group (the (a)/(b)/(c) language) · flow · op_circle · snowflake (frozen backbone) · image_thumb · embedding_space (contrastive panels) · loss_tag · bracket

sciglyph.layout — pre-flight collision detection.

Catching layout bugs before you save

When a figure breaks, it is almost never the artwork — it is the layout. report() uses the real rendered bounding boxes to find overlapping text, so you do not have to hunt for it by eye:

report(fig, ax)
# [sciglyph.layout] 36 text objects
#   ! 'CD4 Treg/-FOXP3' x 'SMR' overlap 92%

It also works from the command line on any script that exposes fig and ax:

python -m sciglyph.layout my_figure.py

It checks three things, each of which shipped a broken figure before it existed:

check what it catches
text overlap two labels drawn over each other
artwork overlap a row of boxes laid out slightly too wide, so each one covers its neighbour — the strings may not overlap at all, so text-level checks miss it entirely
missing glyphs a character the font cannot draw, rendered as an empty box. Symbols typed as literals (, ) are the usual casualty

Two kinds of overlap are deliberately not reported, because they are the layout working: a panel containing its contents, and an unfilled dashed shape — a ring drawn around the thing it annotates.

These are geometric checks. Whether the figure actually reads well still needs your eyes.

Notes from actually shipping these figures

  • Call set_canvas(fig). In [0,1] coordinates a "circle" is r·W wide and r·H tall. On a 12×3 canvas, every circle becomes a rugby ball.
  • Anchor arrows to what feature_stack returns, not to hard-coded coordinates — otherwise changing the number of blocks silently breaks them.
  • Never put symbol codepoints in figure text. (U+2744) is missing from most sans fonts and renders as a tofu box. Draw it (arch.snowflake).
  • Overlapping translucent fills blend into one muddy colour. Keep the fill under alpha=0.15, stroke each curve, and offset the peaks. Tuning alpha alone will not save you.
  • Fonts: Arial/Helvetica are often absent on Linux. RC falls back to Liberation Sans (metric-compatible with Arial) and sets pdf.fonttype=42 so text stays editable in the PDF — a hard requirement at most journals.
  • Don't move elements toward whitespace. Whitespace relocates, it does not disappear. Decide which row an element belongs to, move it as a group, then verify with the quadrant ink distribution.

Honest scope

This gets you clean flat schematics combined with data panels — the register of a Nature/Science overview figure or a TPAMI architecture diagram. It will not reproduce hand-drawn illustration (shaded organs, textured cells, gradients). For that, embed a CC-BY asset and cite it rather than fake it.

Who maintains this

Guo Cheng, University of Chinese Academy of Sciences — medical imaging and machine learning methods. This tool came out of needing to regenerate a figure every time the numbers changed, and not wanting to redraw it by hand each time.

Corrections, bug reports and feature requests all go to Issues. Please open one rather than emailing: a public answer helps whoever hits the same thing next, and it is searchable.

Other things from the same desk

Written while trying to get papers out, so they tend to be useful at the same points in that process:

  • scholarcheck — verify that a citation actually exists, and audit a whole .bib in CI
  • docxaudit — find what your converter silently dropped from a .docx
  • world-model-map — a map of open-source world models and where their authors say they break
  • kakeya-conjecture-lab — an interactive lab for the Kakeya conjecture, with a box-counting meter

License

MIT © Guo Cheng

Download files

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

Source Distribution

sciglyph-0.2.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

sciglyph-0.2.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file sciglyph-0.2.0.tar.gz.

File metadata

  • Download URL: sciglyph-0.2.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.9

File hashes

Hashes for sciglyph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7e1e6e4309f165225884001f18b148a1a2ab97d2785f3817b5b2d330e661fb80
MD5 dee0574f51b86db2867653e7ef63b16b
BLAKE2b-256 d96150a83b77777246aa3196a8551f8fa3135822f3b249d889ad40c00ac5b242

See more details on using hashes here.

File details

Details for the file sciglyph-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sciglyph-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.9

File hashes

Hashes for sciglyph-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98e6e69bb428f834df739c0c6fc4da491964a42e3f7fa7fc57f586c56a64a807
MD5 102d1080a4e9256740238a5f9106a9d3
BLAKE2b-256 27ba55ce97a098b4df81021896fc215b90caf10d58ba5144e4ef9c9b4fe93b87

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

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