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,\smalland\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#
What a journal fixes for its figures. |
|
Lengths derived from a preset. Sizes are in PostScript points. |
Functions#
Millimetres to inches. |
|
Centimetres to inches. |
|
PostScript (big) points to inches. |
|
TeX points to inches. |
|
TeX points to PostScript points, the unit of matplotlib font sizes. |
|
PostScript points to TeX points. |
|
Look up a preset by key ( |
|
First installed TrueType face among |
|
Capital height of |
|
Derive the figure style for |
|
Derive the style for |
|
Context manager form of :func: |
|
Figure at the exact column width of |
|
Shrink the figure height to its content, keeping the width. |
|
Save |
|
Letter the panels of a figure, top left of each, in one style. |
|
Closest positions to sorted |
|
Label lines at their ends instead of in a legend. |
|
Direct labels where they touch no data, otherwise :func: |
|
Label a horizontal reference line at one of its ends. |
|
Colour and ISO 128-2 line type of data series |
|
Legend inside the axes where it covers no data, otherwise above them. |
|
Plain numbers from 0.1 to 1000, powers of ten outside, never an offset. |
|
|
|
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.tex_pt_to_bp(value: float) float#
TeX points to PostScript points, the unit of matplotlib font sizes.
- 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_sizesin TeX points (\normalsize,\small,\footnotesizeof the LaTeX class in its two-column layout, or of the published page where no class reproduces it),min_textandmin_linein PostScript points.Nonemeans 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.
- widths: collections.abc.Mapping[str, float]#
None
- 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
candidatesor 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
- 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.
- 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 oftheme(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
journaland 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_themedoes) unlessstyleis given, in which case the caller manages rcParams. The height isheightinches, or the width timesaspect(panel height over width, default :data:PANEL_ASPECT) timesnrows / ncols.
Returns
(fig, axes)as :func:matplotlib.pyplot.subplotsdoes.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(defaultsavefig.dpi), or stops shrinking. Returns the new height in inches.Added in version 1.14.0.
- chemparseplot.plot.journal.save_figure(fig: matplotlib.figure.Figure, path: str | os.PathLike[str], *, dpi: float | None = None, **savefig_kw: Any) pathlib.Path#
Save
figat 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_stylesets to the journal resolution.Added in version 1.14.0.
- 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.
targetis 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.fmtdefaults 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
ythat are at leastpitchapart.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.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=Falselabels 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\smalland one ISO 3098-1 character space from the line. When every end is taken the line goes into a :func:smart_legendinstead. 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.
handlesdefault to the labelled artists ofaxandlabelsto 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 itsloc="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.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.