py-probelab
Shared ProbeLab utilities. Install as py-probelab, import as probelab.
uv add py-probelab
# or: pip install py-probelab
Today this is brand colors and matplotlib styling, so every chart we publish looks like it came from the same place. More common utilities will land here over time.
Charts
import matplotlib.pyplot as plt
import numpy as np
import probelab.plot as pplot
pplot.use()
fig, ax = plt.subplots()
ax.plot(np.arange(100), np.random.randn(100).cumsum(), label="dht")
ax.set_title("Lookup latency")
ax.set_xlabel("time")
ax.legend()
pplot.watermark(fig, loc="lower right")
fig.savefig("latency.png")
use() applies the theme globally for the rest of the process. Inside library
code, or when you only want it for one figure, use the context manager instead
so the caller's session is left alone:
with pplot.style():
fig, ax = plt.subplots()
...
Importing probelab.plot registers the theme with matplotlib itself, so you can
skip the helpers entirely and compose it with any other style:
import probelab.plot # noqa: F401 - registers the style
plt.style.use("probelab-dark")
plt.style.use(["probelab-dark", "seaborn-v0_8-poster"])
Watermark
pplot.watermark(fig) # centered, faint
pplot.watermark(ax, loc="upper right") # per-panel
pplot.watermark(fig, alpha=0.2, zoom=0.1) # more visible, smaller
Pass a Figure to place the mark in figure coordinates (usually what you want
for a multi-panel chart) or an Axes to place it within one panel. Positions
are center, upper left, upper right, lower left, lower right.
Colors
probelab.colors has no third-party imports, so it is safe to use from
dashboards, reports and terminal output as well as from plotting code:
from probelab import colors
colors.PALETTE # the 9 categorical series colors, in cycle order
colors.categorical(4) # first 4 of them
colors.PRIMARY # "#FFD7C5" - titles, axis labels
colors.BASE_100 # page/figure background
Fonts
The package vendors eight static DM Sans weights and registers them with matplotlib on first use, so charts render identically on a laptop and in CI without anyone installing fonts system-wide.
pplot.fonts_available() # False means charts fell back to a system sans
pplot.use(fonts=False) # prefer a system-wide DM Sans instead
Development
uv sync
uv run pytest
uv build
Changing the theme
src/probelab/plot/styles/probelab-dark.mplstyle is the source of truth for the
theme; src/probelab/colors.py mirrors its color tokens for non-matplotlib
consumers. A test asserts the two agree, so change them together.
Two things to know about editing .mplstyle files:
- Hex colors are written without a leading
#, because#starts a comment there.figure.facecolor: 2e3438, not#2e3438- the latter silently parses as an empty value and raises on load. - Font weights must match a weight the vendored family actually declares, or
matplotlib logs a
findfontwarning on every render. DM Sans ExtraLight declares 250, not 200.
Licensing
The code is MIT. The bundled DM Sans family is redistributed under the SIL Open
Font License 1.1 (src/probelab/plot/assets/fonts/OFL.txt).
Release files for py-probelab 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_probelab-0.1.0.tar.gz | 278.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_probelab-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 558.5 kB
Release files / py_probelab-0.1.0.tar.gz
| Download URL | py_probelab-0.1.0.tar.gz |
|---|---|
| Size | 278.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ffd03ffbfcd865a7c1df063f22fe5f47d0bda8f806d6a659a3b876ad4cf7778b
|
|
BLAKE2b-256 checksum How to use checksums |
9c12db020f5ef2b943f7c7cca0363d00dbf4f16ad2c9dce11e07eb4ad70377b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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 / py_probelab-0.1.0-py3-none-any.whl
| Download URL | py_probelab-0.1.0-py3-none-any.whl |
|---|---|
| Size | 280.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a003e9d5912d44eded198f175dd31b1c8c385a3a098f6b41b7c8c7bbd8419d20
|
|
BLAKE2b-256 checksum How to use checksums |
43df922e8afbf177b64cabe539bdf0b32bddefaeeee1b3ea01039a5504ea2f61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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}
|