Skip to content

Commit 7df2184

Browse files
committed
start refactoring using style sheets
1 parent c794244 commit 7df2184

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

scripts/advanced-plots.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Script to generate all the advanced plots
7+
import pathlib
8+
79
import numpy as np
810
import matplotlib as mpl
911
import matplotlib.pyplot as plt
1012

11-
fig = plt.figure(figsize=(0.4, 0.4))
12-
mpl.rcParams['axes.linewidth'] = 0.5
13-
mpl.rcParams['xtick.major.size'] = 0.0
14-
mpl.rcParams['ytick.major.size'] = 0.0
13+
14+
mpl.style.use(pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle')
15+
16+
fig = plt.figure()
1517
d = 0.01
1618
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
1719

1820
# Step plot
1921
# -----------------------------------------------------------------------------
2022
X = np.linspace(0, 10, 16)
2123
Y = 4 + 2*np.sin(2*X)
22-
ax.step(X, Y, color="C1", linewidth=0.75)
24+
ax.step(X, Y, color="C1")
2325
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
2426
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
2527
ax.grid(linewidth=0.125)

scripts/basic-plots.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,40 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Script to generate all the basic plots
7+
import pathlib
8+
79
import numpy as np
810
import matplotlib as mpl
911
import matplotlib.pyplot as plt
1012

11-
fig = plt.figure(figsize=(0.4, 0.4))
12-
mpl.rcParams['axes.linewidth'] = 0.5
13-
mpl.rcParams['xtick.major.size'] = 0.0
14-
mpl.rcParams['ytick.major.size'] = 0.0
13+
14+
mpl.style.use(pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle')
15+
16+
fig = plt.figure()
1517
d = 0.01
1618
ax = fig.add_axes([d, d, 1 - 2 * d, 1 - 2 * d])
1719

1820
# Basic line plot
1921
# -----------------------------------------------------------------------------
2022
X = np.linspace(0, 10, 100)
2123
Y = 4 + 2*np.sin(2*X)
22-
ax.plot(X, Y, color="C1", linewidth=0.75)
24+
ax.plot(X, Y, color="C1")
2325
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
2426
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
25-
ax.grid(linewidth=0.125)
27+
ax.grid()
2628
plt.savefig("../figures/basic-plot.pdf")
2729
ax.clear()
2830

2931
# Basic line plot (color)blaPwd
3032

3133
# -----------------------------------------------------------------------------
3234
X = np.linspace(0, 10, 100)
33-
Y = 4 + 2 * np.sin(2 * X)
34-
ax.plot(X, Y, color="black", linewidth=0.75)
35+
Y = 4 + 2*np.sin(2*X)
36+
ax.plot(X, Y, color="black")
3537
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
3638
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
37-
ax.grid(linewidth=0.125)
39+
ax.grid()
3840
plt.savefig("../figures/basic-plot-color.pdf")
3941
ax.clear()
4042

@@ -47,7 +49,7 @@
4749
edgecolor="white", facecolor="C1", linewidth=0.25)
4850
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
4951
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
50-
ax.grid(linewidth=0.125)
52+
ax.grid()
5153
plt.savefig("../figures/basic-scatter.pdf")
5254
ax.clear()
5355

@@ -61,7 +63,7 @@
6163
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
6264
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
6365
ax.set_axisbelow(True)
64-
ax.grid(linewidth=0.125)
66+
ax.grid()
6567
plt.savefig("../figures/basic-bar.pdf")
6668
ax.clear()
6769

@@ -142,7 +144,7 @@
142144
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
143145
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
144146
ax.set_axisbelow(True)
145-
ax.grid(linewidth=0.125, color="0.75")
147+
ax.grid(color="0.75")
146148
plt.savefig("../figures/basic-fill.pdf")
147149
ax.clear()
148150

@@ -157,6 +159,6 @@
157159
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
158160
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
159161
ax.set_axisbelow(True)
160-
ax.grid(linewidth=0.125, color="0.75")
162+
ax.grid(color="0.75")
161163
plt.savefig("../figures/basic-quiver.pdf")
162164
ax.clear()

styles/plotlet.mplstyle

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
figure.figsize: 0.4, 0.4
2+
3+
figure.constrained_layout.h_pad: 0.01
4+
figure.constrained_layout.w_pad: 0.01
5+
figure.constrained_layout.hspace: 0.01
6+
figure.constrained_layout.wspace: 0.01
7+
8+
axes.linewidth: 0.5
9+
10+
grid.linewidth: 0.2
11+
12+
lines.linewidth: 0.75
13+
14+
xtick.major.size: 0.0
15+
ytick.major.size: 0.0

0 commit comments

Comments
 (0)