spacr.figure_font

The font figures are drawn in: the one that ships with spaCR.

Matplotlib’s default is DejaVu Sans, and asking for “Helvetica” on a Linux machine that has no Helvetica silently falls back to it too – so figures came out in a different face from the interface around them, and in a different face on each contributor’s machine.

spaCR ships Open Sans (spacr/resources/font/open_sans), so the face is always present. REGISTERING IT IS THE POINT: setting the rcParam alone names a family matplotlib may not have, and a name it cannot resolve is a silent fallback rather than an error. Adding the bundled files to the font manager is what makes the name resolve on a machine where Open Sans was never installed.

Functions

bundled_faces(→ List[str])

Every bundled TrueType or OpenType face.

font_dir(→ str)

The directory holding the bundled static faces.

use_open_sans_for_figures(→ bool)

Register the bundled faces with Matplotlib's font manager.

Module Contents

spacr.figure_font.bundled_faces() → List[str][source]

Every bundled TrueType or OpenType face.

Returns:

Absolute paths in filename order. A missing or unreadable font directory returns an empty list rather than raising – a figure drawn in the wrong font is a blemish, and never a reason for a plot not to appear.

spacr.figure_font.font_dir() → str[source]

The directory holding the bundled static faces.

Returns:

an absolute path. It exists in an installed build too, because the fonts are package data.

spacr.figure_font.use_open_sans_for_figures() → bool[source]

Register the bundled faces with Matplotlib’s font manager.

Idempotent and safe to call before any figure is drawn. This deliberately does not alter process-wide rcParams: the two house-style helpers put Open Sans in their scoped parameter dictionaries instead.

Returns:

whether Open Sans is now resolvable by name.