Plot Style¶
This module provides opt-in Nature-journal-style formatting for dot-explorer plots: Helvetica/Arial fonts at 5–7 pt, 0.5 pt line and axes widths, no top/right spines, outward ticks, and 300 dpi tight-bbox figure export defaults.
Use the context manager to style a single plot:
from dot_explorer import DotPlotter, SequenceIndex, nature_style
idx = SequenceIndex(k=10)
idx.add_sequence("seq1", "ACGTACGTACGTACGTACGT")
idx.add_sequence("seq2", "TACGTACGTACGTACGTACG")
plotter = DotPlotter(idx)
with nature_style():
fig = plotter.plot(output_path="dotplot.png", dpi=300)
Note
Explicit keyword arguments always override rcParams, and
DotPlotter.plot passes its own dpi argument (default 150) to
savefig. Pass dpi=300 explicitly, as above, to save at Nature's
recommended resolution; the savefig.dpi/savefig.bbox defaults in
the style apply to plain plt.savefig() calls that omit those
arguments.
Or apply the style globally for the session:
Constants¶
NATURE_RC = {'font.family': 'sans-serif', 'font.sans-serif': ['Helvetica', 'Arial', 'Helvetica Neue', 'Liberation Sans', 'Nimbus Sans', 'DejaVu Sans'], 'font.size': 7.0, 'axes.titlesize': 7.0, 'axes.labelsize': 7.0, 'xtick.labelsize': 6.0, 'ytick.labelsize': 6.0, 'legend.fontsize': 6.0, 'legend.title_fontsize': 7.0, 'figure.titlesize': 7.0, 'lines.linewidth': 0.5, 'axes.linewidth': 0.5, 'grid.linewidth': 0.5, 'patch.linewidth': 0.5, 'xtick.major.width': 0.5, 'ytick.major.width': 0.5, 'xtick.minor.width': 0.5, 'ytick.minor.width': 0.5, 'axes.spines.top': False, 'axes.spines.right': False, 'xtick.direction': 'out', 'ytick.direction': 'out', 'savefig.dpi': 300, 'savefig.bbox': 'tight'}
module-attribute
¶
rcParams implementing Nature journal figure-formatting guidelines.
Keys mirror :data:matplotlib.rcParams: Helvetica/Arial sans-serif fonts
at 5-7 pt, 0.5 pt line and axes widths, no top/right spines, outward
ticks, and 300 dpi tight-bbox savefig defaults.
Functions¶
nature_style()
¶
Return a context manager that applies the Nature style temporarily.
Inside the with block :data:matplotlib.rcParams reflects
:data:NATURE_RC; on exit the previous rcParams are restored,
even if an exception was raised.
Returns:
| Type | Description |
|---|---|
AbstractContextManager
|
A :func: |
Examples:
>>> import matplotlib
>>> from dot_explorer.style import nature_style
>>> with nature_style():
... assert matplotlib.rcParams['savefig.dpi'] == 300
Source code in dot_explorer/style.py
use_nature_style()
¶
Apply the Nature style globally to :data:matplotlib.rcParams.
Unlike :func:nature_style, the change persists for the rest of the
session (or until rcParams are reset, e.g. via
:func:matplotlib.rcdefaults).
Returns:
| Type | Description |
|---|---|
None
|
This function mutates :data: |
Examples:
>>> import matplotlib
>>> from dot_explorer.style import use_nature_style
>>> use_nature_style()
>>> matplotlib.rcParams['axes.spines.top']
False
>>> matplotlib.rcdefaults() # reset to matplotlib library defaults