API reference¶
Everything below is re-exported at the top level: import journalfig as jf then jf.subplots(...).
journalfig ¶
Publication-ready matplotlib themes for twelve scientific publishers.
Each theme encodes the figure requirements the publisher actually documents -- column widths, font sizes, panel label conventions, minimum line weights, and accepted file formats -- so a figure can be retargeted from one journal to another by changing a single string.
Example
import matplotlib.pyplot as plt import journalfig as jf jf.use("elsevier") fig, ax = plt.subplots(figsize=jf.figsize("elsevier", "single")) _ = ax.plot([1, 2, 3], [1, 4, 9], label=r"$S(q)$")
Author: Achraf Atila (achraf.atila@bam.de)
JournalSpec
dataclass
¶
Figure requirements for one publisher.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable publisher name. |
widths_mm |
dict[str, float]
|
Allowed figure widths keyed by layout name. |
max_height_mm |
float | None
|
Maximum figure height, or |
min_width_mm |
float | None
|
Minimum figure width, or |
text_min_pt |
float | None
|
Smallest permitted size for normal text, or |
text_max_pt |
float | None
|
Largest permitted size for normal text, or |
sub_min_pt |
float | None
|
Smallest permitted size for sub/superscripts, or |
min_lettering_mm |
float | None
|
Minimum printed glyph height, or |
min_marker_mm |
float | None
|
Minimum printed data-point diameter, or |
min_linewidth_pt |
float | None
|
Minimum printed line weight, or |
panel_label_fmt |
str
|
Format string for panel labels, e.g. |
panel_label_upper |
bool
|
Label panels |
panel_label_pt |
float
|
Panel label font size. |
raster_dpi |
int | None
|
The publisher's stated minimum resolution for raster artwork, and the resolution
:func: |
formats |
tuple[str, ...]
|
File formats :func: |
submission_formats |
tuple[str, ...]
|
What the publisher accepts as final artwork, which is not the same
question as what is useful to have on disk. Drives the draft warning in
:func: |
font_families |
tuple[str, ...]
|
Typefaces the publisher asks for, most preferred first. |
font_substitutes |
tuple[str, ...]
|
Metrically compatible stand-ins. Type designers cut these to the same
widths, so a figure set in one is indistinguishable in layout from the real thing;
:func: |
tiff_compression |
str | None
|
Pillow compression passed through when a TIFF is written, or |
style |
ThemeStyle
|
Rendering choices for this theme. Deliberately a separate object: nothing in it comes
from the publisher, and :func: |
Source code in src/journalfig/_specs.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
ThemeStyle
dataclass
¶
How a theme draws, as opposed to what its publisher requires.
Nothing in this class is quoted from an author guide. No publisher states a tick length, a marker
diameter, or a legend handle length; these are journalfig's own choices about what looks right at
the sizes the publisher does state, and they are kept out of :class:JournalSpec so that
"every number is traceable to a publisher document" stays literally true of that class.
:func:journalfig.check validates against :class:JournalSpec only, never against this.
Values are in points unless the name says otherwise. The defaults are the Nature theme's, which is the most conservative of the three; a theme built for a larger base font wants larger ticks.
Attributes:
| Name | Type | Description |
|---|---|---|
axes_linewidth |
float
|
Weight of the axes frame, and of patch and hatch edges with it. |
grid_linewidth |
float
|
Weight of grid lines, and of minor tick marks with them. |
tick_major_size |
float
|
Length of major tick marks. Applied to both axes -- x and y are never given different tick geometry, and hand-writing them separately invited asymmetry. |
tick_minor_size |
float
|
Length of minor tick marks, both axes. |
tick_major_width |
float
|
Weight of major tick marks, both axes. |
tick_minor_width |
float
|
Weight of minor tick marks, both axes. |
tick_pad |
float
|
Gap between a tick mark and its label, both axes. |
marker_size |
float
|
Default marker diameter for line plots. |
marker_edge_width |
float
|
Default marker edge weight. |
errorbar_capsize |
float
|
Half-width of an errorbar cap. |
legend_handlelength |
float
|
Length of the sample line in a legend entry. |
title_weight |
str
|
|
title_location |
str
|
|
mathtext_fontset |
str
|
|
font_family_category |
str
|
|
font_stack |
tuple[str, ...]
|
The concrete fallback chain matplotlib searches, most preferred first, ending in
a face matplotlib bundles so the theme degrades rather than fails. This is a third thing
from |
Source code in src/journalfig/_specs.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
Source
dataclass
¶
The publisher document a theme's numbers were read from.
Publishers revise their artwork guidelines, so a specification is only as trustworthy as the date
it was last checked against the source. retrieved records that date.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
Where the document was obtained. |
title |
str
|
The document's own title. |
version |
str | None
|
The document's stated edition or date, or |
retrieved |
str
|
ISO date on which the numbers in :data: |
Source code in src/journalfig/_specs.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
Violation
dataclass
¶
A single departure from a publisher's figure requirements.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
Short category, e.g. |
message |
str
|
Human-readable description including the measured and required values. |
Source code in src/journalfig/_core.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
FontStatus
dataclass
¶
What a requested typeface actually resolved to on this machine.
Attributes:
| Name | Type | Description |
|---|---|---|
requested |
tuple[str, ...]
|
The families asked for, in the order matplotlib searches them. |
resolved |
str
|
The family that will really be drawn. |
path |
str
|
The font file backing |
status |
str
|
|
Source code in src/journalfig/_core.py
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
JournalFigWarning ¶
Bases: UserWarning
Warning raised for a figure that departs from a publisher's requirements.
A dedicated class so these can be filtered without silencing every other UserWarning:
warnings.filterwarnings("ignore", category=journalfig.JournalFigWarning).
Source code in src/journalfig/_core.py
50 51 52 53 54 55 | |
use ¶
use(journal: str, *, usetex: bool = False, base_size: float | None = None) -> None
Apply a journal theme to the global matplotlib state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key ( |
required |
usetex
|
bool
|
Render text with the system LaTeX installation instead of mathtext. Slower, and
requires |
False
|
base_size
|
float | None
|
Override the theme's base font size in points; every other font size is scaled by the same factor. Useful for maths-heavy Elsevier figures, where the publisher's 6 pt sub/superscript floor needs a base of at least 8.6 pt. |
None
|
Example
use("elsevier", base_size=9) plt.rcParams["font.size"] 9.0
Source code in src/journalfig/_core.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
context ¶
context(journal: str, **kwargs: Any) -> Iterator[None]
Apply a theme temporarily, restoring the previous rcParams on exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
**kwargs
|
Any
|
Forwarded to :func: |
{}
|
Yields:
| Type | Description |
|---|---|
None
|
|
Example
plt.rcParams["font.size"] = 11.0 with context("nature"): ... pass plt.rcParams["font.size"] 11.0
Source code in src/journalfig/_core.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
figsize ¶
figsize(journal: str, width: str | float = 'single', *, ratio: float = GOLDEN, height_mm: float | None = None) -> tuple[float, float]
Return an exact figure size in inches for a journal column width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
width
|
str | float
|
A layout name from the journal's spec ( |
'single'
|
ratio
|
float
|
Height divided by width. Defaults to the inverse golden ratio. |
GOLDEN
|
height_mm
|
float | None
|
Explicit height in millimetres, overriding |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Example
tuple(round(v, 4) for v in figsize("nature", "single")) (3.5039, 2.1656) tuple(round(v, 4) for v in figsize("aps", "double", ratio=0.4)) (7.0, 2.8)
Source code in src/journalfig/_core.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
figure ¶
figure(journal: str, width: str | float = 'single', *, ratio: float = GOLDEN, height_mm: float | None = None, **kwargs: Any) -> Figure
Create a figure at an exact journal column width.
Prefer this over plt.figure(figsize=figsize(...)): it survives the pixel rounding that
interactive backends apply, and it records the requested size so :func:save can re-assert it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
width
|
str | float
|
Layout name or an explicit width in millimetres. |
'single'
|
ratio
|
float
|
Height divided by width. |
GOLDEN
|
height_mm
|
float | None
|
Explicit height in millimetres, overriding |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
The new figure, sized exactly. |
Example
use("nature") round(float(figure("nature", "double").get_size_inches()[0]) * 25.4, 4) 183.0
Source code in src/journalfig/_core.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
subplots ¶
subplots(journal: str, nrows: int = 1, ncols: int = 1, *, width: str | float = 'single', ratio: float = GOLDEN, height_mm: float | None = None, **kwargs: Any) -> tuple[Figure, Any]
Create a figure and axes grid at an exact journal column width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
nrows
|
int
|
Number of subplot rows. |
1
|
ncols
|
int
|
Number of subplot columns. |
1
|
width
|
str | float
|
Layout name or an explicit width in millimetres. |
'single'
|
ratio
|
float
|
Height divided by width. |
GOLDEN
|
height_mm
|
float | None
|
Explicit height in millimetres, overriding |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Any]
|
|
Example
use("elsevier") fig, axs = subplots("elsevier", 2, 2, width="double") round(float(fig.get_size_inches()[0]) * 25.4, 4) 190.0
Source code in src/journalfig/_core.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
mosaic ¶
mosaic(journal: str, layout: str | HashableList[Hashable], *, width: str | float = 'single', ratio: float = GOLDEN, height_mm: float | None = None, width_ratios: Sequence[float] | None = None, height_ratios: Sequence[float] | None = None, **kwargs: Any) -> tuple[Figure, dict[str, Axes]]
Create panels of unequal size from an ASCII sketch of the layout.
Each cell of the sketch names the panel that occupies it; repeating a name over neighbouring
cells makes that panel span them, and "." leaves a cell empty. width_ratios and
height_ratios then set how large the underlying grid's columns and rows are relative to each
other, so panels need not be multiples of one cell size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
layout
|
str | HashableList[Hashable]
|
Panel layout, either a multi-line string with one character per cell or nested lists of panel names (use lists for names longer than one character). |
required |
width
|
str | float
|
Layout name or an explicit width in millimetres. |
'single'
|
ratio
|
float
|
Height divided by width. Layouts of more than one row usually need a value well above the default inverse golden ratio. |
GOLDEN
|
height_mm
|
float | None
|
Explicit height in millimetres, overriding |
None
|
width_ratios
|
Sequence[float] | None
|
Relative widths of the grid columns; one entry per column. |
None
|
height_ratios
|
Sequence[float] | None
|
Relative heights of the grid rows; one entry per row. |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
dict[str, Axes]
|
order the names first appear when reading the sketch left to right, top to bottom. |
Example
use("nature") fig, panels = mosaic("nature", "AAB\nCCB", width="double", width_ratios=[1, 1, 1.4]) list(panels) ['A', 'B', 'C'] round(float(fig.get_size_inches()[0]) * 25.4, 4) 183.0
Source code in src/journalfig/_core.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
gridspec ¶
gridspec(journal: str, nrows: int = 1, ncols: int = 1, *, width: str | float = 'single', ratio: float = GOLDEN, height_mm: float | None = None, width_ratios: Sequence[float] | None = None, height_ratios: Sequence[float] | None = None, **kwargs: Any) -> tuple[Figure, GridSpec]
Create a figure and an empty grid to place spanning panels on by hand.
Use this when a layout is easier to express as slices than as a sketch -- a panel spanning
columns 0 and 1 of row 0 is fig.add_subplot(gs[0, :2]). For anything that fits in a sketch,
:func:mosaic is shorter. Both size the figure identically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
nrows
|
int
|
Number of grid rows. |
1
|
ncols
|
int
|
Number of grid columns. |
1
|
width
|
str | float
|
Layout name or an explicit width in millimetres. |
'single'
|
ratio
|
float
|
Height divided by width. |
GOLDEN
|
height_mm
|
float | None
|
Explicit height in millimetres, overriding |
None
|
width_ratios
|
Sequence[float] | None
|
Relative widths of the grid columns; one entry per column. |
None
|
height_ratios
|
Sequence[float] | None
|
Relative heights of the grid rows; one entry per row. |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, GridSpec]
|
|
Example
use("aps") fig, gs = gridspec("aps", 2, 3, width="double", height_ratios=[1, 1.5]) wide = fig.add_subplot(gs[0, :2]) tall = fig.add_subplot(gs[:, 2]) gs.get_geometry() (2, 3)
Source code in src/journalfig/_core.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
panel_labels ¶
panel_labels(axes: Iterable[Axes] | Axes, *, journal: str | None = None, fmt: str | None = None, labels: Iterable[str] | None = None, dx: float = -16.0, dy: float = 3.0, weight: str = 'bold', size: float | None = None, **kwargs: Any) -> list[Text]
Add journal-styled panel labels to a set of axes.
Nature wants bare lowercase letters (a, b); APS and Elsevier want parentheses
((a), (b)). The label is offset in points from each axes' top-left corner, so it stays
put regardless of figure size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axes
|
Iterable[Axes] | Axes
|
A single axes or an iterable of them, in reading order. Accepts the array returned
by |
required |
journal
|
str | None
|
Theme key or alias. Defaults to the active theme. |
None
|
fmt
|
str | None
|
Format string applied to each letter, overriding the journal default. |
None
|
labels
|
Iterable[str] | None
|
Explicit label strings, overriding the generated letters. |
None
|
dx
|
float
|
Horizontal offset in points from the axes' left edge. |
-16.0
|
dy
|
float
|
Vertical offset in points from the axes' top edge. |
3.0
|
weight
|
str
|
Font weight. |
'bold'
|
size
|
float | None
|
Font size in points. Defaults to the journal's panel label size. |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[Text]
|
The created text artists, in the order the axes were given. |
Example
use("aps") fig, axs = plt.subplots(1, 2) tuple(t.get_text() for t in panel_labels(axs)) ('(a)', '(b)')
Source code in src/journalfig/_core.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
label_lines ¶
label_lines(ax: Axes, *, labels: Iterable[str] | None = None, offset: float = 3.0, **kwargs: Any) -> list[Text]
Label each line at its right-hand end instead of in a legend.
A legend costs space and makes the reader look up a colour before they can read the plot. At a single-column width that lookup is the most expensive thing on the page, and putting the name beside the line removes it. The label takes the line's own colour, so the association survives a greyscale print only if the linestyles differ too -- which the themes' property cycle ensures.
Labels are drawn outside the axes and are not clipped, so leave room for them: ax.margins(x=0.2)
before calling, or set an explicit upper x-limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes whose lines should be labelled. |
required |
labels
|
Iterable[str] | None
|
Explicit label strings, overriding each line's own label. Must match the number of labelled lines. |
None
|
offset
|
float
|
Horizontal gap in points between the end of the line and its label. |
3.0
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[Text]
|
The created text artists, in the order the lines were drawn. |
Example
use("elsevier") fig, ax = subplots("elsevier") _ = ax.plot([1, 2, 3], [1, 4, 9], label="Series A") _ = ax.plot([1, 2, 3], [2, 5, 10], label="Series B") tuple(t.get_text() for t in label_lines(ax)) ('Series A', 'Series B')
Source code in src/journalfig/_core.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
check ¶
check(fig: Figure, *, journal: str | None = None, warn: bool = True) -> list[Violation]
Check a figure against a publisher's stated figure requirements.
Inspects text sizes (including the 0.7x shrink matplotlib applies to maths sub/superscripts),
printed glyph height, line weights, marker diameters, the figure's own dimensions, and which
typeface the machine will actually draw with. A metrically compatible substitute passes; a
silent fall back to something else does not. See :func:fonts for the full picture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The figure to inspect. |
required |
journal
|
str | None
|
Theme key or alias. Defaults to the active theme. |
None
|
warn
|
bool
|
Emit a |
True
|
Returns:
| Type | Description |
|---|---|
list[Violation]
|
Every violation found, in discovery order. Empty means the figure complies with the |
list[Violation]
|
machine-checkable parts of the spec. |
Example
use("aps") fig, ax = subplots("aps") _ = ax.set_xlabel("q", fontsize=4) sorted({v.kind for v in check(fig, warn=False)}) ['lettering']
Source code in src/journalfig/_core.py
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
fonts ¶
fonts(journal: str | None = None, fig: Figure | None = None) -> dict[str, FontStatus]
Report the typefaces this machine will really draw with.
matplotlib substitutes silently when a requested family is missing. A theme asking for Arial or Times renders in DejaVu on a machine that has neither -- it still looks fine on screen, and the figure breaks the publisher's font requirement. Run this before trusting a figure produced somewhere other than where the theme was tested, an HPC node especially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str | None
|
Theme key or alias. Defaults to the active theme. |
None
|
fig
|
Figure | None
|
Read the families from this figure's own text artists instead of from the global
rcParams. Pass it for any figure this process did not just draw under the theme --
without it the answer describes the caller's settings, not the figure. Note that an
artist which inherited the generic name |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
dict[str, FontStatus]
|
class: |
dict[str, FontStatus]
|
entry per custom mathtext face; reading a figure gives |
|
dict[str, FontStatus]
|
and |
|
dict[str, FontStatus]
|
chooses the fonts then, and empty for a figure carrying no visible text. |
Example
use("nature") fonts()["text"].requested[0] 'Arial' fig, ax = subplots("nature") _ = ax.set_xlabel("q") fonts(fig=fig)["text"].requested[0] 'Arial'
Source code in src/journalfig/_core.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | |
save ¶
save(fig: Figure, path: str | Path, *, journal: str | None = None, formats: Iterable[str] | None = None, dpi: int | None = None, validate: bool = True, pil_kwargs: dict[str, Any] | None = None, svg_text: str | None = None) -> list[Path]
Save a figure in the formats the target publisher accepts.
Writes with bbox_inches=None so the declared column width survives into the file; a tight
bounding box would crop it by around one percent. TIFFs are LZW-compressed by default, which is
lossless: an Elsevier single-column figure lands at a few hundred kB rather than 7.5 MB.
The size actually written is reported through the journalfig logger at INFO level, so it stays
out of the way in a pipeline. Raise that one logger to see it --
logging.getLogger("journalfig").setLevel("INFO") -- rather than the root logger, which also
switches on fontTools and its dozen subsetting lines per PDF.
Every journal writes PDF, SVG and PNG by default: the file you submit, one to edit in Inkscape or
Illustrator, and one for a talk or a preview. Pass formats= for anything else the backend
supports -- TIFF for Elsevier, EPS for an APS colour-online-only figure -- and convert from the
SVG for whatever else a publisher asks for.
SVG keeps live, editable text (svg.fonttype: none), which means it renders correctly only
where the theme's typeface is installed; :func:fonts reports what that will be. The draft
warning fires once per call, and only when nothing written is a format the publisher takes as
final artwork -- so a PNG beside a PDF is silent, and a PNG on its own is not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The figure to write. |
required |
path
|
str | Path
|
Output path. Any extension is replaced by each requested format. |
required |
journal
|
str | None
|
Theme key or alias. Defaults to the active theme. |
None
|
formats
|
Iterable[str] | None
|
File formats to write, overriding the journal defaults. |
None
|
dpi
|
int | None
|
Resolution for raster formats. Defaults to the journal's requirement. |
None
|
validate
|
bool
|
Run :func: |
True
|
pil_kwargs
|
dict[str, Any] | None
|
Passed to Pillow for raster formats, replacing the journal's TIFF compression.
Pass |
None
|
svg_text
|
str | None
|
How text is stored in an SVG. |
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The paths written, in the order requested. |
Example
import tempfile use("elsevier") fig, ax = subplots("elsevier") with tempfile.TemporaryDirectory() as d: ... # validate=False keeps this example independent of whether the machine running it has ... # Arial installed; leave it on in real use, where that is exactly what you want to know. ... tuple(p.suffix for p in save(fig, Path(d) / "fig1", formats=["pdf"], validate=False)) ('.pdf',)
Source code in src/journalfig/_core.py
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
active ¶
active() -> str | None
Return the theme key applied by the most recent :func:use call.
Returns:
| Type | Description |
|---|---|
str | None
|
The active theme key, or |
Example
use("nature") active() 'nature'
Source code in src/journalfig/_core.py
163 164 165 166 167 168 169 170 171 172 173 174 | |
register ¶
register() -> None
Add the bundled themes to matplotlib's in-process style library.
Makes plt.style.use("nature") work without going through :func:use. This only touches the
running interpreter; nothing is written to ~/.matplotlib/stylelib.
Example
register() "nature" in plt.style.available True
Source code in src/journalfig/_core.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
style_file ¶
style_file(journal: str) -> Path
Return the path to a theme's .mplstyle file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or journal alias. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the style file shipped with the package. |
Example
style_file("prb").name 'aps.mplstyle'
Source code in src/journalfig/_core.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
resolve ¶
resolve(journal: str) -> str
Resolve a journal name or alias to a theme key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or a known journal alias, case-insensitive. |
required |
Returns:
| Type | Description |
|---|---|
str
|
One of |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the name is not a known theme or alias. |
Example
resolve("Acta Materialia") 'elsevier' resolve("PRB") 'aps'
Source code in src/journalfig/_specs.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
get_spec ¶
get_spec(journal: str) -> JournalSpec
Look up the :class:JournalSpec for a journal name or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or a known journal alias. |
required |
Returns:
| Type | Description |
|---|---|
JournalSpec
|
The matching specification. |
Example
get_spec("nature").widths_mm["single"] 89.0
Source code in src/journalfig/_specs.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 | |
source ¶
source(journal: str) -> Source
Look up the publisher document a theme's numbers came from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journal
|
str
|
Theme key or a known journal alias. |
required |
Returns:
| Type | Description |
|---|---|
Source
|
The document, including the date its numbers were last checked. |
Example
print(source("PRB")) APS Journals Style Guide for Authors, November 2024 (retrieved 2026-07-28)
Source code in src/journalfig/_specs.py
804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
mm_to_inch ¶
mm_to_inch(value_mm: float) -> float
Convert millimetres to inches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_mm
|
float
|
Length in millimetres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The same length in inches. |
Example
round(mm_to_inch(89.0), 4) 3.5039
Source code in src/journalfig/_specs.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |