-
Notifications
You must be signed in to change notification settings - Fork 29
/
example-plot.py
47 lines (36 loc) · 1.25 KB
/
example-plot.py
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
38
39
40
41
42
43
44
45
46
47
###################################################################
# This file shows how to create a plot that integrates seamlessly
# with the quantumarticle document class using matplotlib and rsmf.
# This script requires the packages numpy, matplotlib and rsmf.
###################################################################
import numpy as np
import matplotlib.pyplot as plt
import rsmf
# Get formatter specifications from tex file
fmt = rsmf.setup("quantum-template.tex")
# Generate dummy spectral data
x = np.linspace(400, 800, 200)
y = (
30 / (4 + ((x - 550) / 4) ** 2)
+ 30 / (12 + ((x - 650) / 12) ** 2)
+ 0.001 * x
+ np.random.normal(0, 0.1, 200)
)
fig = fmt.figure()
# plot data
data = plt.scatter(x, y, color="C0", alpha=0.7, marker="x")
# plot fits
y_fit1 = 30 / (4 + ((x - 550) / 4) ** 2)
plt.plot(x, y_fit1, color="C1", ls="--")
y_fit2 = 30 / (12 + ((x - 650) / 12) ** 2)
plt.plot(x, y_fit2, color="C2", ls="--")
y_fit3 = 0.001 * x
plt.plot(x, y_fit3, color="C3", ls="--")
y_fit = y_fit1 + y_fit2 + y_fit3
(fit,) = plt.plot(x, y_fit, color="C0")
plt.xlabel("$\\lambda$ [nm]")
plt.ylabel("$I$ [arb. un.]")
plt.legend([data, fit], ["Data", "Fit"])
plt.tight_layout(pad=0.0)
# Save the figure in PDF format
plt.savefig("example-plotpdf")