-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_quickstart.py
More file actions
37 lines (27 loc) · 1.09 KB
/
01_quickstart.py
File metadata and controls
37 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Quickstart — publication-ready figure in under 10 lines.
Steps:
1. Apply a journal preset with plotstyle.use() to configure fonts and sizes.
2. Create a correctly-sized figure with plotstyle.figure().
3. Save with plotstyle.savefig() to embed fonts and enforce the required DPI.
Output: output/quickstart_nature.pdf
"""
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import plotstyle
OUTPUT_DIR = Path(__file__).parent / "output"
OUTPUT_DIR.mkdir(exist_ok=True)
# The context manager restores all modified rcParams when the block exits.
with plotstyle.use("nature"):
# columns=1 → single-column width (89 mm); use columns=2 for full width
fig, ax = plotstyle.figure("nature", columns=1)
x = np.linspace(0, 2 * np.pi, 200)
ax.plot(x, np.sin(x), label="sin(x)")
ax.plot(x, np.cos(x), label="cos(x)")
ax.set_xlabel("Phase (rad)")
ax.set_ylabel("Amplitude (a.u.)")
ax.legend()
# journal="nature" enforces DPI >= 300 and embeds TrueType fonts
plotstyle.savefig(fig, OUTPUT_DIR / "quickstart_nature.pdf", journal="nature")
plt.close(fig)