Skip to content

Commit 755fdee

Browse files
committed
start refactoring using style sheets
1 parent f97d66b commit 755fdee

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

scripts/advanced-plots.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
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

scripts/basic-plots.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
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

@@ -31,10 +33,10 @@
3133
# -----------------------------------------------------------------------------
3234
X = np.linspace(0, 10, 100)
3335
Y = 4+2*np.sin(2*X)
34-
ax.plot(X, Y, color="black", linewidth=0.75)
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

@@ -95,7 +97,7 @@
9597
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
9698
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
9799
# ax.set_axisbelow(True)
98-
# ax.grid(linewidth=0.125, color="0.75")
100+
# ax.grid(color="0.75")
99101
plt.savefig("../figures/basic-contour.pdf")
100102
ax.clear()
101103

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

@@ -155,6 +157,6 @@
155157
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
156158
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
157159
ax.set_axisbelow(True)
158-
ax.grid(linewidth=0.125, color="0.75")
160+
ax.grid(color="0.75")
159161
plt.savefig("../figures/basic-quiver.pdf")
160162
ax.clear()

styles/plotlet.mplstyle

Lines changed: 15 additions & 0 deletions
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)