chemparseplot.plot.journal#

Journal figure presets and the publication style derived from them.

A :class:JournalPreset holds what a journal fixes for its figures: column widths, the font sizes of its LaTeX class, the smallest lettering and line weight it accepts, the raster resolution it asks for and the faces it recommends. :func:figure_style derives every other length from those numbers, so a figure needs no hand-tuned sizes:

  • Text uses the class sizes (\normalsize, \small and \footnotesize), converted from TeX points (72.27 per inch) to the PostScript points matplotlib uses (72 per inch), and never goes below the journal minimum. Axis labels and panel letters are at the body size, tick labels and legends at \small.

  • Line widths follow the narrow : wide : extra-wide = 1 : 2 : 4 series of ISO 128-2:2020. The narrow width is one step of the series (a factor sqrt(2)) below the ISO 3098-1:2015 type B letter stroke d = h/10, where h is the capital height of the face at the body size, and never goes below the journal minimum.

  • Tick lengths, gaps and marker sizes are ISO 3098-1 type B proportions of the same h: x-height 0.7 h for major ticks, descender 0.3 h for minor ticks, word space 0.6 h between ticks and labels, character space 0.2 h around panels, the mixed-case baseline pitch 1.5 h between stacked labels, and markers as tall as a capital.

Added in version 1.14.0.

Module Contents#

Classes#

JournalPreset

What a journal fixes for its figures.

JournalStyle

Lengths derived from a preset. Sizes are in PostScript points.

Functions#

mm

Millimetres to inches.

cm

Centimetres to inches.

bp

PostScript (big) points to inches.

tex_pt

TeX points to inches.

tex_pt_to_bp

TeX points to PostScript points, the unit of matplotlib font sizes.

bp_to_tex_pt

PostScript points to TeX points.

get_preset

Look up a preset by key ("acs") or journal alias ("jctc").

resolve_font

First installed TrueType face among candidates or their metric clones.

cap_height

Capital height of face (default: the current rcParams face) per point of size.

figure_style

Derive the figure style for journal.

apply_style

Derive the style for journal and set it in the global rcParams.

journal_style

Context manager form of :func:apply_style.

journal_figure

Figure at the exact column width of journal, with its style applied.

fit_height

Shrink the figure height to its content, keeping the width.

_output_dpi

save_figure

Save fig at its exact size, with fonts embedded and fixed metadata.

_version

_panel_axes

label_panels

Letter the panels of a figure, top left of each, in one style.

_column

_spread

Closest positions to sorted y that are at least pitch apart.

direct_labels

Label lines at their ends instead of in a legend.

_no_marker

_overlaps_data

label_lines

Direct labels where they touch no data, otherwise :func:smart_legend.

label_hline

Label a horizontal reference line at one of its ends.

series_style

Colour and ISO 128-2 line type of data series index.

smart_legend

Legend inside the axes where it covers no data, otherwise above them.

_axes

sci_axis

Plain numbers from 0.1 to 1000, powers of ten outside, never an offset.

relative_error

|value - reference| / |reference|, floored at machine epsilon.

log_error_axis

Log axis for errors: labelled decades as powers of ten, unlabelled minors.

Data#

API#

chemparseplot.plot.journal.MM_PER_INCH#

25.4

chemparseplot.plot.journal.MM_PER_CM#

10.0

chemparseplot.plot.journal.BP_PER_INCH#

72.0

chemparseplot.plot.journal.TEX_PT_PER_INCH#

72.27

chemparseplot.plot.journal.mm(value: float) → float#

Millimetres to inches.

chemparseplot.plot.journal.cm(value: float) → float#

Centimetres to inches.

chemparseplot.plot.journal.bp(value: float) → float#

PostScript (big) points to inches.

chemparseplot.plot.journal.tex_pt(value: float) → float#

TeX points to inches.

chemparseplot.plot.journal.tex_pt_to_bp(value: float) → float#

TeX points to PostScript points, the unit of matplotlib font sizes.

chemparseplot.plot.journal.bp_to_tex_pt(value: float) → float#

PostScript points to TeX points.

chemparseplot.plot.journal._STROKE#

None

chemparseplot.plot.journal._X_HEIGHT#

None

chemparseplot.plot.journal._DESCENDER#

None

chemparseplot.plot.journal._CHAR_SPACE#

None

chemparseplot.plot.journal._WORD_SPACE#

None

chemparseplot.plot.journal._BASELINE_PITCH#

None

chemparseplot.plot.journal._LINE_STEP#

‘sqrt(…)’

chemparseplot.plot.journal._WIDE#

2.0

chemparseplot.plot.journal._EXTRA_WIDE#

4.0

chemparseplot.plot.journal._DOT#

0.5

chemparseplot.plot.journal._GAP#

3.0

chemparseplot.plot.journal._DASH#

12.0

chemparseplot.plot.journal._LONG_DASH#

24.0

chemparseplot.plot.journal.LINE_TYPES#

((‘01’, ‘continuous’, ‘solid’), (‘02’, ‘dashed’, (0, ())), (‘07’, ‘dotted’, (0, ())), (‘04’, ‘long-d…

chemparseplot.plot.journal.SI_POWERLIMITS#

()

chemparseplot.plot.journal.PANEL_ASPECT#

None

chemparseplot.plot.journal._METRIC_CLONES#

None

chemparseplot.plot.journal._TRUETYPE_SUFFIXES#

None

chemparseplot.plot.journal._FALLBACK_FACE#

‘DejaVu Sans’

class chemparseplot.plot.journal.JournalPreset#

What a journal fixes for its figures.

Widths and heights are in inches, class_sizes in TeX points (\normalsize, \small, \footnotesize of the LaTeX class in its two-column layout, or of the published page where no class reproduces it), min_text and min_line in PostScript points. None means the journal states no value. Where a guideline gives a length in two units, the two are rounded conversions of each other and the smaller is used, so the figure fits both.

Added in version 1.14.0.

key: str#

None

name: str#

None

widths: collections.abc.Mapping[str, float]#

None

max_height: float | None#

None

class_sizes: tuple[float, float, float]#

None

min_text: float#

None

min_line: float | None#

None

raster_dpi: int#

None

fonts: tuple[str, ...]#

None

panel_label: str#

None

sources: tuple[str, ...]#

None

width(columns: str = 'single') → float#

Figure width in inches for columns.

chemparseplot.plot.journal.ACS#

‘JournalPreset(…)’

chemparseplot.plot.journal.AIP#

‘JournalPreset(…)’

chemparseplot.plot.journal.ELSEVIER#

‘JournalPreset(…)’

chemparseplot.plot.journal.RSC#

‘JournalPreset(…)’

chemparseplot.plot.journal.PRESETS: dict[str, chemparseplot.plot.journal.JournalPreset]#

None

chemparseplot.plot.journal.ALIASES#

None

chemparseplot.plot.journal.DEFAULT_JOURNAL#

‘acs’

chemparseplot.plot.journal.get_preset(journal: str | chemparseplot.plot.journal.JournalPreset = DEFAULT_JOURNAL) → chemparseplot.plot.journal.JournalPreset#

Look up a preset by key ("acs") or journal alias ("jctc").

Added in version 1.14.0.

chemparseplot.plot.journal.resolve_font(candidates: collections.abc.Iterable[str]) → str#

First installed TrueType face among candidates or their metric clones.

Falls back to DejaVu Sans, which matplotlib ships.

Added in version 1.14.0.

chemparseplot.plot.journal.cap_height(face: str | None = None) → float#

Capital height of face (default: the current rcParams face) per point of size.

Measured from the outline of “H”.

Added in version 1.14.0.

class chemparseplot.plot.journal.JournalStyle#

Lengths derived from a preset. Sizes are in PostScript points.

Added in version 1.14.0.

preset: chemparseplot.plot.journal.JournalPreset#

None

font: str#

None

body: float#

None

small: float#

None

footnote: float#

None

cap: float#

None

narrow: float#

None

wide: float#

None

extra: float#

None

tick: float#

None

minor_tick: float#

None

pad: float#

None

gap: float#

None

marker: float#

None

textcolor: str#

None

facecolor: str#

None

property pitch: float#

Smallest baseline spacing for \small labels stacked in a column.

property marker_large: float#

Marker one step of the sqrt(2) series above :attr:marker, for points that must stand out from the data (minima, saddles).

width(columns: str = 'single') → float#

Figure width in inches for columns, as :meth:JournalPreset.width.

halo(color: str | None = None) → list#

Path effects that outline text or lines in color (default the text colour), one narrow width wide, so they read on any fill.

rc() → dict#

rcParams for this style.

chemparseplot.plot.journal.figure_style(journal: str | chemparseplot.plot.journal.JournalPreset = DEFAULT_JOURNAL, *, font: str | None = None, theme: str | chemparseplot.plot.theme.PlotTheme = 'ruhi') → chemparseplot.plot.journal.JournalStyle#

Derive the figure style for journal.

Text is set in font, by default the face of theme (a theme name or :class:~chemparseplot.plot.theme.PlotTheme), which also sets the text and background colours. Where the theme’s face is not installed, the faces the journal names stand in.

Added in version 1.14.0.

chemparseplot.plot.journal.apply_style(journal: str | chemparseplot.plot.journal.JournalPreset = DEFAULT_JOURNAL, **kwargs: Any) → chemparseplot.plot.journal.JournalStyle#

Derive the style for journal and set it in the global rcParams.

Keyword arguments go to :func:figure_style.

Added in version 1.14.0.

chemparseplot.plot.journal.journal_style(journal: str | chemparseplot.plot.journal.JournalPreset = DEFAULT_JOURNAL, **kwargs: Any) → collections.abc.Iterator[chemparseplot.plot.journal.JournalStyle]#

Context manager form of :func:apply_style.

Added in version 1.14.0.

chemparseplot.plot.journal.journal_figure(journal: str | chemparseplot.plot.journal.JournalPreset = DEFAULT_JOURNAL, columns: str = 'single', *, nrows: int = 1, ncols: int = 1, aspect: float | None = None, height: float | None = None, style: chemparseplot.plot.journal.JournalStyle | None = None, **subplots_kw: Any) → tuple[matplotlib.figure.Figure, Any]#

Figure at the exact column width of journal, with its style applied.

The style goes into the global rcParams (as

Func:

chemparseplot.plot.theme.setup_publication_theme does) unless style is given, in which case the caller manages rcParams. The height is height inches, or the width times aspect (panel height over width, default :data:PANEL_ASPECT) times nrows / ncols.

Returns (fig, axes) as :func:matplotlib.pyplot.subplots does.

Added in version 1.14.0.

chemparseplot.plot.journal.fit_height(fig: matplotlib.figure.Figure, *, dpi: float | None = None) → float#

Shrink the figure height to its content, keeping the width.

Axes with a fixed aspect (energy landscapes) leave empty bands under constrained layout; this removes them. Stops when the height changes by less than one output pixel at dpi (default savefig.dpi), or stops shrinking. Returns the new height in inches.

Added in version 1.14.0.

chemparseplot.plot.journal._output_dpi(fig, dpi: float | None = None) → float#
chemparseplot.plot.journal.save_figure(fig: matplotlib.figure.Figure, path: str | os.PathLike[str], *, dpi: float | None = None, **savefig_kw: Any) → pathlib.Path#

Save fig at its exact size, with fonts embedded and fixed metadata.

No tight bounding box is applied, so the page keeps the column width. PDF and SVG carry no creation date and SVG ids come from a fixed salt, so a script writes the same bytes on every run. Raster formats use savefig.dpi, which :func:apply_style sets to the journal resolution.

Added in version 1.14.0.

chemparseplot.plot.journal._version() → str#
chemparseplot.plot.journal._panel_axes(fig) → list#
chemparseplot.plot.journal.label_panels(target: matplotlib.figure.Figure | collections.abc.Sequence[matplotlib.axes.Axes] | numpy.ndarray, labels: collections.abc.Sequence[str] | None = None, *, fmt: str | None = None, journal: str | chemparseplot.plot.journal.JournalPreset | None = None, fontweight: str = 'normal') → list[matplotlib.text.Text]#

Letter the panels of a figure, top left of each, in one style.

target is a figure or a sequence of axes (default order: as added to the figure). Each letter sits above the axes, its left edge on the left edge of the panel’s tick and axis labels; panels in one grid column share that edge. fmt defaults to the journal’s panel label format, “(a)”.

Added in version 1.14.0.

chemparseplot.plot.journal._column(ax)#
chemparseplot.plot.journal._spread(y: numpy.ndarray, pitch: float) → numpy.ndarray#

Closest positions to sorted y that are at least pitch apart.

Least squares under the spacing constraints: subtract k * pitch, take the isotonic (non-decreasing) regression by pool-adjacent-violators, add the offsets back.

chemparseplot.plot.journal.direct_labels(ax: matplotlib.axes.Axes, lines: collections.abc.Sequence[matplotlib.lines.Line2D] | None = None, *, side: str = 'right') → list[matplotlib.text.Annotation]#

Label lines at their ends instead of in a legend.

Labels use each line’s label and a shade of its colour that reaches the WCAG text contrast on the axes background. Labels that would collide are moved apart to at least one baseline pitch (ISO 3098-1 b2, 1.5 capital heights), as little as possible in the least-squares sense. Constrained layout makes room for the labels, which moves the line ends; the labels are spread again until the ends move by less than one output pixel at savefig.dpi, or stop settling.

Added in version 1.14.0.

chemparseplot.plot.journal._INSIDE#

(‘upper right’, ‘upper left’, ‘lower left’, ‘lower right’, ‘center right’, ‘center left’, ‘lower cen…

chemparseplot.plot.journal._no_marker(marker) → bool#
chemparseplot.plot.journal._overlaps_data(ax, bbox, renderer, exclude=()) → bool#
chemparseplot.plot.journal.label_lines(ax: matplotlib.axes.Axes, lines: collections.abc.Sequence[matplotlib.lines.Line2D] | None = None, *, fallback: bool = True, **legend_kw: Any) → list[matplotlib.text.Annotation] | list[matplotlib.legend.Legend]#

Direct labels where they touch no data, otherwise :func:smart_legend.

Returns the label texts, or a one-element list holding the legend. With fallback=False labels that would touch data are removed and an empty list is returned, so a figure can try its panels in turn.

Added in version 1.14.0.

chemparseplot.plot.journal.label_hline(ax: matplotlib.axes.Axes, line: matplotlib.lines.Line2D, label: str, *, color: matplotlib.typing.ColorType | None = None, ignore: collections.abc.Sequence[matplotlib.artist.Artist] = ()) → matplotlib.text.Annotation | matplotlib.legend.Legend#

Label a horizontal reference line at one of its ends.

Tries the right end above the line, then below it, then the left end above and below, and keeps the first label that touches no data. Artists in ignore, such as faint context lines, may be crossed. Labels are \small and one ISO 3098-1 character space from the line. When every end is taken the line goes into a :func:smart_legend instead. Returns the label text or the legend.

Added in version 1.14.0.

chemparseplot.plot.journal.series_style(index: int, background: matplotlib.typing.ColorType = 'white') → dict#

Colour and ISO 128-2 line type of data series index.

Colours are the Ruhi line colours that reach the WCAG 1.4.11 contrast for graphics on background; line types cycle independently, so series differ in both, stay apart in greyscale and for readers with colour-vision deficiencies, and a pair repeats only after the least common multiple of the two cycle lengths.

Added in version 1.14.0.

chemparseplot.plot.journal.smart_legend(ax: matplotlib.axes.Axes, handles: collections.abc.Sequence[matplotlib.artist.Artist] | None = None, labels: collections.abc.Sequence[str] | None = None, **kwargs: Any) → matplotlib.legend.Legend#

Legend inside the axes where it covers no data, otherwise above them.

handles default to the labelled artists of ax and labels to the handles’ labels. Matplotlib draws one legend per axes, so the entries of a legend already there are kept. Tries matplotlib’s inside locations in the order its loc="best" search does and keeps the first whose box touches no line, marker, filled area, image or text. When every location covers data (filled contours always do), the legend goes in one row above the axes, where constrained layout makes room for it.

Added in version 1.14.0.

chemparseplot.plot.journal._axes(ax, axis: str)#
chemparseplot.plot.journal.sci_axis(ax: matplotlib.axes.Axes, axis: str = 'y') → None#

Plain numbers from 0.1 to 1000, powers of ten outside, never an offset.

Follows NIST SP 811’s advice on numerical values (see

Data:

SI_POWERLIMITS); the power is written with mathtext.

Added in version 1.14.0.

chemparseplot.plot.journal.relative_error(value: numpy.typing.ArrayLike, reference: numpy.typing.ArrayLike) → numpy.ndarray#

|value - reference| / |reference|, floored at machine epsilon.

Errors below the working precision are not resolvable and would vanish from a log axis; they are shown at epsilon of the result dtype instead.

Added in version 1.14.0.

chemparseplot.plot.journal.log_error_axis(ax: matplotlib.axes.Axes, axis: str = 'y') → None#

Log axis for errors: labelled decades as powers of ten, unlabelled minors.

Non-positive values are clipped; use :func:relative_error to keep exact zeros visible at machine epsilon.

Added in version 1.14.0.