milia.plot.style#
Matplotlib house style for publication figures.
SciencePlots’ science style through twiga’s
configure_matlib_style, with these overrides: serif type (Times New Roman)
set through LaTeX, 10 pt labels, thin rules, no grid, no legend frame and the
project palette. Figures are authored one panel at a time at the size they will
occupy (panel()) and saved as PDF, so LaTeX composes the sub-figures.
LaTeX is on by default; call configure(latex=False) on a machine without
TeX. With LaTeX on, any text from data must go through texsafe().
Module Attributes
Text width of the target document, in inches (455.24 pt). |
|
The overrides layered on twiga's base style. |
|
Space between the x-axis label and a legend placed below it, in points. |
Functions
|
Apply the house style globally. |
Switch to matplotlib's non-interactive Agg backend. |
|
|
Left and bottom spines only, ticks pointing out, no minor ticks. |
|
Height of a golden-ratio figure of a given width. |
|
Legend centred below the axes; |
|
Axis limits around every array, padded by a share of the range. |
|
|
|
Put every |
|
Save a figure as PDF (and a 600 dpi PNG preview), tightly cropped, then close it. |
|
Lay out the figure and its legends as |
|
The house style with hand-drawn paths, for illustrations rather than results. |
|
The house style for the duration of a block, restoring the previous settings afterwards. |
|
Escape text for LaTeX; a no-op when |
- milia.plot.style.TEXTWIDTH = 6.3#
Text width of the target document, in inches (455.24 pt).
- milia.plot.style.RC: dict[str, Any] = {'axes.edgecolor': '#222222', 'axes.grid': False, 'axes.labelcolor': '#222222', 'axes.labelsize': 10, 'axes.linewidth': 0.5, 'axes.prop_cycle': cycler('color', ['#107591', '#00c0bf', '#f69a48', '#fdcd49', '#8da798', '#a19368', '#525252', '#a6761d', '#7035b7', '#cf166e']), 'figure.dpi': 150, 'font.family': 'serif', 'font.serif': ['Times New Roman', 'DejaVu Serif'], 'font.size': 10, 'legend.fontsize': 10, 'legend.frameon': False, 'legend.title_fontsize': 10, 'lines.linewidth': 1.0, 'mathtext.fontset': 'dejavuserif', 'savefig.bbox': 'tight', 'savefig.pad_inches': 0.05, 'text.color': '#222222', 'xtick.color': '#222222', 'xtick.labelsize': 10, 'ytick.color': '#222222', 'ytick.labelsize': 10}#
The overrides layered on twiga’s base style.
- milia.plot.style.golden(width=6.3)#
Height of a golden-ratio figure of a given width.
Examples
>>> golden(10.0) 6.18
- milia.plot.style.panel(fraction=0.48, aspect=0.618)#
figsizefor a panel occupying a share of the text width.Authoring each panel at the size it will finally occupy keeps type the same size across a composed figure; scaling panels in LaTeX does not.
- Parameters:
- Return type:
- Returns:
(width, height)in inches.
Examples
>>> [round(v, 3) for v in panel(0.5, aspect=1.0)] [3.15, 3.15]
- milia.plot.style.configure(latex=True, size=12.0)#
Apply the house style globally.
Calls twiga’s
configure_matlib_style(SciencePlots’sciencestyle and the LaTeX toolchain) and layersRCon top.- Parameters:
- Return type:
Examples
>>> configure(latex=False) >>> import matplotlib as mpl >>> mpl.rcParams["font.family"] ['serif']
- milia.plot.style.style(latex=True, **overrides)#
The house style for the duration of a block, restoring the previous settings afterwards.
- Parameters:
- Yields:
Nothing; the style is active inside the block.
Examples
>>> import matplotlib as mpl >>> with style(latex=False, **{"lines.linewidth": 3.0}): ... mpl.rcParams["lines.linewidth"] 3.0
- milia.plot.style.sketch(latex=True, scale=1.2, length=130, randomness=3, **overrides)#
The house style with hand-drawn paths, for illustrations rather than results.
Only the paths wobble; text stays in the house serif.
- Parameters:
- Yields:
Nothing; the style is active inside the block.
Examples
>>> import matplotlib as mpl >>> with sketch(latex=False): ... mpl.rcParams["path.sketch"] (1.2, 130.0, 3.0)
- milia.plot.style.filebackend()#
Switch to matplotlib’s non-interactive Agg backend.
For scripts that only save figures: an interactive backend fails on a Python built without Tcl/Tk, as uv installs it. Notebooks should not call it.
Examples
>>> filebackend()
- Return type:
- milia.plot.style.pad(*arrays, frac=0.04, floor=1e-09)#
Axis limits around every array, padded by a share of the range.
A deliberate margin, so a point at the extreme does not sit on the spine.
- Parameters:
- Return type:
- Returns:
(low, high), orNonewhen there is nothing finite to pad.
Examples
>>> pad([0.0, 1.0]) (-0.04, 1.04) >>> pad([]) is None True
- milia.plot.style.texsafe(text)#
Escape text for LaTeX; a no-op when
text.usetexis off.Use on any string from data placed in a figure while LaTeX is on.
Examples
>>> import matplotlib as mpl >>> mpl.rcParams["text.usetex"] = False >>> texsafe("a_b & c") 'a_b & c'
- milia.plot.style.finish(ax)#
Left and bottom spines only, ticks pointing out, no minor ticks.
Examples
>>> import matplotlib.pyplot as plt >>> ax = finish(plt.subplots()[1]) >>> ax.spines["top"].get_visible() False
- milia.plot.style.GAP = 3.0#
Space between the x-axis label and a legend placed below it, in points.
- milia.plot.style.legend(ax, ncol=3, handles=None, labels=None)#
Legend centred below the axes;
place()moves it just under the x-axis label after layout.- Parameters:
- Return type:
Examples
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> _ = ax.plot([0, 1], label="x") >>> legend(ax) >>> ax.get_legend() is not None True
- milia.plot.style.place(fig)#
Put every
legend()just under its axes’ x-axis label, in as many columns as fit.Called by
save()andshow()after layout.Examples
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> _ = ax.plot([0, 1], label="x") >>> legend(ax) >>> place(fig)
- milia.plot.style.show(fig)#
Lay out the figure and its legends as
save()does, then display it.Examples
>>> import matplotlib.pyplot as plt >>> show(plt.subplots()[0])
- milia.plot.style.save(fig, path, png=True)#
Save a figure as PDF (and a 600 dpi PNG preview), tightly cropped, then close it.
- Parameters:
- Return type:
- Returns:
The PDF path.
Examples
>>> import tempfile, matplotlib.pyplot as plt >>> from pathlib import Path >>> fig, ax = plt.subplots() >>> save(fig, Path(tempfile.mkdtemp()) / "figure", png=False).suffix '.pdf'