Skip to content

Commit 36607cd

Browse files
authored
Merge pull request #88 from jimustafa/revamp-with-style-sheets
revamp using style sheets
2 parents 3d7d3ff + cfa709d commit 36607cd

20 files changed

+433
-353
lines changed

Diff for: Makefile

+13-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ logos:
1515
figures:
1616
# generate the figures
1717
cd scripts && for script in *.py; do echo $$script; MPLBACKEND="agg" python $$script; done
18-
# crop the figures
19-
cd figures && for figure in *.pdf; do echo $$figure; pdfcrop $$figure $$figure; done
20-
# regenerate some figures that should not be cropped
21-
cd scripts && MPLBACKEND="agg" python styles.py
18+
# crop some of the figures
19+
cd figures && pdfcrop adjustments.pdf adjustments.pdf
20+
cd figures && pdfcrop annotate.pdf annotate.pdf
21+
cd figures && pdfcrop annotation-arrow-styles.pdf annotation-arrow-styles.pdf
22+
cd figures && pdfcrop anatomy.pdf anatomy.pdf
23+
cd figures && pdfcrop colornames.pdf colornames.pdf
24+
cd figures && pdfcrop fonts.pdf fonts.pdf
25+
cd figures && pdfcrop markers.pdf markers.pdf
26+
cd figures && pdfcrop text-alignments.pdf text-alignments.pdf
27+
cd figures && pdfcrop tick-formatters.pdf tick-formatters.pdf
28+
cd figures && pdfcrop tick-locators.pdf tick-locators.pdf
29+
cd figures && pdfcrop tip-font-family.pdf tip-font-family.pdf
30+
cd figures && pdfcrop tip-hatched.pdf tip-hatched.pdf
2231

2332
.PHONY: cheatsheets
2433
cheatsheets:

Diff for: cheatsheets.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
\setlength\parindent{0pt}
105105
\setlength{\tabcolsep}{2pt}
106106
\baselineskip=0pt
107-
\setlength\columnsep{0.5em}
107+
\setlength\columnsep{1.75mm}
108108

109109

110110
% --- Macros ------------------------------------------------------------------

Diff for: scripts/adjustements.py

+45-26
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,82 @@
22
# Matplotlib cheat sheet
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
5+
import pathlib
56

67
import numpy as np
8+
import matplotlib as mpl
79
import matplotlib.pyplot as plt
810
import matplotlib.patches as mpatches
911
from matplotlib.collections import PatchCollection
1012

1113

12-
fig = plt.figure(figsize=(4.25, 4.25 * 95/115))
13-
ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1,
14-
xlim=(0-5, 100+10), ylim=(-10, 80+5), xticks=[], yticks=[])
14+
mpl.style.use([
15+
pathlib.Path(__file__).parent/'../styles/base.mplstyle',
16+
])
17+
mpl.rc('font', size=4)
18+
mpl.rc('lines', linewidth=0.5)
19+
mpl.rc('patch', linewidth=0.5)
20+
21+
22+
subplots_kw = dict(
23+
figsize=(5.7/2.54, 5.7/2.54 * 95/115),
24+
subplot_kw=dict(
25+
frameon=False,
26+
aspect=1,
27+
xlim=(0-5, 100+10),
28+
ylim=(-10, 80+5),
29+
xticks=[],
30+
yticks=[],
31+
),
32+
)
33+
34+
(fig, ax) = plt.subplots(**subplots_kw)
1535

1636

1737
box = mpatches.FancyBboxPatch(
1838
(0, 0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2),
19-
linewidth=1., facecolor="0.9", edgecolor="black")
39+
facecolor="0.9", edgecolor="black")
2040
ax.add_artist(box)
2141

2242
box = mpatches.FancyBboxPatch(
2343
(0, 0), 100, 75, mpatches.BoxStyle("Round", pad=0, rounding_size=0),
24-
linewidth=1., facecolor="white", edgecolor="black")
44+
facecolor="white", edgecolor="black")
2545
ax.add_artist(box)
2646

2747

2848
box = mpatches.Rectangle(
2949
(5, 5), 45, 30, zorder=10,
30-
linewidth=1.0, facecolor="white", edgecolor="black")
50+
facecolor="white", edgecolor="black")
3151
ax.add_artist(box)
3252

3353
box = mpatches.Rectangle(
3454
(5, 40), 45, 30, zorder=10,
35-
linewidth=1.0, facecolor="white", edgecolor="black")
55+
facecolor="white", edgecolor="black")
3656
ax.add_artist(box)
3757

3858
box = mpatches.Rectangle(
3959
(55, 5), 40, 65, zorder=10,
40-
linewidth=1.0, facecolor="white", edgecolor="black")
60+
facecolor="white", edgecolor="black")
4161
ax.add_artist(box)
4262

4363
# Window button
4464
X, Y = [5, 10, 15], [79, 79, 79]
45-
plt.scatter(X, Y, s=75, zorder=10,
46-
edgecolor="black", facecolor="white", linewidth=1)
65+
plt.scatter(X, Y, s=20, zorder=10,
66+
edgecolor="black", facecolor="white")
4767

4868

4969
# Window size extension
5070
X, Y = [0, 0], [0, -8]
51-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
71+
plt.plot(X, Y, color="black", linestyle=":", clip_on=False)
5272

5373
X, Y = [100, 100], [0, -8]
54-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
74+
plt.plot(X, Y, color="black", linestyle=":", clip_on=False)
5575

5676
X, Y = [100, 108], [0, 0]
57-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
77+
plt.plot(X, Y, color="black", linestyle=":", clip_on=False)
5878

5979
X, Y = [100, 108], [75, 75]
60-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
80+
plt.plot(X, Y, color="black", linestyle=":", clip_on=False)
6181

6282

6383
def ext_arrow(p0, p1, p2, p3):
@@ -69,7 +89,7 @@ def ext_arrow(p0, p1, p2, p3):
6989
ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0,
7090
length_includes_head=True, width=.4,
7191
head_width=2, head_length=2, color="black")
72-
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], linewidth=.9, color="black")
92+
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], linewidth=.5, color="black")
7393

7494

7595
def int_arrow(p0, p1):
@@ -85,45 +105,44 @@ def int_arrow(p0, p1):
85105
x = 0
86106
y = 10
87107
ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )
88-
ax.text(x+9.5, y, "left", ha="left", va="center", size="x-small", zorder=20)
108+
ax.text(x+9.5, y, "left", ha="left", va="center", zorder=20)
89109

90110
x += 50
91111
ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )
92-
ax.text(x-4.5, y, "wspace", ha="right", va="center", size="x-small", zorder=20)
112+
ax.text(x-4.5, y, "wspace", ha="right", va="center", zorder=20)
93113

94114
x += 45
95115
ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )
96-
ax.text(x-4.5, y, "right", ha="right", va="center", size="x-small", zorder=20)
116+
ax.text(x-4.5, y, "right", ha="right", va="center", zorder=20)
97117

98118
y = 0
99119
x = 25
100120
ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )
101-
ax.text(x, y+9.5, "bottom", ha="center", va="bottom", size="x-small", zorder=20)
121+
ax.text(x, y+9.5, "bottom", ha="center", va="bottom", zorder=20)
102122

103123
y += 35
104124
ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )
105-
ax.text(x, y-4.5, "hspace", ha="center", va="top", size="x-small", zorder=20)
125+
ax.text(x, y-4.5, "hspace", ha="center", va="top", zorder=20)
106126

107127
y += 35
108128
ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )
109-
ax.text(x, y-4.5, "top", ha="center", va="top", size="x-small", zorder=20)
129+
ax.text(x, y-4.5, "top", ha="center", va="top", zorder=20)
110130

111131
int_arrow((0, -5), (100, -5))
112132
ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30,
113-
ha="center", va="center", size="x-small")
133+
ha="center", va="center")
114134

115135
int_arrow((105, 0), (105, 75))
116136
ax.text(105, 75/2, "figure height", backgroundcolor="white", zorder=30,
117-
rotation="vertical", ha="center", va="center", size="x-small")
137+
rotation="vertical", ha="center", va="center")
118138

119139
int_arrow((55, 62.5), (95, 62.5))
120140
ax.text(75, 62.5, "axes width", backgroundcolor="white", zorder=30,
121-
ha="center", va="center", size="x-small")
141+
ha="center", va="center")
122142

123143
int_arrow((62.5, 5), (62.5, 70))
124144
ax.text(62.5, 35, "axes height", backgroundcolor="white", zorder=30,
125-
rotation="vertical", ha="center", va="center", size="x-small")
145+
rotation="vertical", ha="center", va="center")
126146

127147

128148
plt.savefig("../figures/adjustments.pdf")
129-
# plt.show()

Diff for: scripts/advanced-plots.py

+42-50
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,51 @@
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
15-
d = 0.01
16-
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
13+
14+
mpl.style.use([
15+
pathlib.Path(__file__).parent/'../styles/base.mplstyle',
16+
pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle',
17+
])
18+
19+
20+
subplot_kw = dict(
21+
xlim=(0, 8), xticks=np.arange(1, 8),
22+
ylim=(0, 8), yticks=np.arange(1, 8),
23+
)
1724

1825
# Step plot
1926
# -----------------------------------------------------------------------------
27+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
2028
X = np.linspace(0, 10, 16)
2129
Y = 4 + 2*np.sin(2*X)
22-
ax.step(X, Y, color="C1", linewidth=0.75)
23-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
24-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
25-
ax.grid(linewidth=0.125)
26-
plt.savefig("../figures/advanced-step.pdf")
27-
ax.clear()
30+
ax.step(X, Y, color="C1")
31+
ax.grid()
32+
fig.savefig("../figures/advanced-step.pdf")
2833

2934
# Violin plot
3035
# -----------------------------------------------------------------------------
36+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
3137
np.random.seed(10)
3238
D = np.random.normal((3, 5, 4), (0.75, 1.00, 0.75), (200, 3))
3339
VP = ax.violinplot(D, [2, 4, 6], widths=1.5,
3440
showmeans=False, showmedians=False, showextrema=False)
3541
for body in VP['bodies']:
3642
body.set_facecolor('C1')
3743
body.set_alpha(1)
38-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
39-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
4044
ax.set_axisbelow(True)
41-
ax.grid(linewidth=0.125)
42-
plt.savefig("../figures/advanced-violin.pdf")
43-
ax.clear()
45+
ax.grid()
46+
fig.savefig("../figures/advanced-violin.pdf")
4447

4548
# Boxplot
4649
# -----------------------------------------------------------------------------
50+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
4751
np.random.seed(10)
4852
D = np.random.normal((3, 5, 4), (1.25, 1.00, 1.25), (100, 3))
4953
VP = ax.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True,
@@ -57,85 +61,74 @@
5761
"linewidth": 0.75},
5862
capprops={"color": "C1",
5963
"linewidth": 0.75})
60-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
61-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
6264
ax.set_axisbelow(True)
63-
ax.grid(linewidth=0.125)
64-
plt.savefig("../figures/advanced-boxplot.pdf")
65-
ax.clear()
65+
ax.grid()
66+
fig.savefig("../figures/advanced-boxplot.pdf")
6667

6768
# Barbs plot
6869
# -----------------------------------------------------------------------------
70+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
6971
np.random.seed(1)
7072
X = [[2, 4, 6]]
7173
Y = [[1.5, 3, 2]]
7274
U = -np.ones((1, 3)) * 0
7375
V = -np.ones((1, 3)) * np.linspace(50, 100, 3)
7476
ax.barbs(X, Y, U, V, barbcolor="C1", flagcolor="C1", length=5, linewidth=0.5)
75-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
76-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
7777
ax.set_axisbelow(True)
78-
ax.grid(linewidth=0.125)
79-
plt.savefig("../figures/advanced-barbs.pdf")
80-
ax.clear()
78+
ax.grid()
79+
fig.savefig("../figures/advanced-barbs.pdf")
8180

8281
# Event plot
8382
# -----------------------------------------------------------------------------
83+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
8484
np.random.seed(1)
8585
X = [2, 4, 6]
8686
D = np.random.gamma(4, size=(3, 50))
8787
ax.eventplot(D, colors="C1", orientation="vertical", lineoffsets=X,
8888
linewidth=0.25)
89-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
90-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
9189
ax.set_axisbelow(True)
92-
ax.grid(linewidth=0.125)
93-
plt.savefig("../figures/advanced-event.pdf")
94-
ax.clear()
90+
ax.grid()
91+
fig.savefig("../figures/advanced-event.pdf")
9592

9693
# Errorbar plot
9794
# -----------------------------------------------------------------------------
95+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
9896
np.random.seed(1)
9997
X = [2, 4, 6]
10098
Y = [4, 5, 4]
10199
E = np.random.uniform(0.5, 1.5, 3)
102100
ax.errorbar(X, Y, E, color="C1", linewidth=0.75, capsize=1)
103-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
104-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
105101
ax.set_axisbelow(True)
106-
ax.grid(linewidth=0.125)
107-
plt.savefig("../figures/advanced-errorbar.pdf")
108-
ax.clear()
102+
ax.grid()
103+
fig.savefig("../figures/advanced-errorbar.pdf")
109104

110105
# Hexbin plot
111106
# -----------------------------------------------------------------------------
107+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
112108
np.random.seed(1)
113109
X = np.random.uniform(1.5, 6.5, 100)
114110
Y = np.random.uniform(1.5, 6.5, 100)
115111
C = np.random.uniform(0, 1, 10000)
116112
ax.hexbin(X, Y, C, gridsize=4, linewidth=0.25, edgecolor="white",
117113
cmap=plt.get_cmap("Wistia"), alpha=1.0)
118-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
119-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
120114
ax.set_axisbelow(True)
121-
ax.grid(linewidth=0.125)
122-
plt.savefig("../figures/advanced-hexbin.pdf")
123-
ax.clear()
115+
ax.grid()
116+
fig.savefig("../figures/advanced-hexbin.pdf")
124117

125118
# Hist plot
126119
# -----------------------------------------------------------------------------
120+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
127121
np.random.seed(1)
128122
X = 4 + np.random.normal(0, 1.5, 200)
129123
ax.hist(X, bins=8, facecolor="C1", linewidth=0.25, edgecolor="white")
130-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
131124
ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10))
132125
ax.set_axisbelow(True)
133-
ax.grid(linewidth=0.125)
134-
plt.savefig("../figures/advanced-hist.pdf")
135-
ax.clear()
126+
ax.grid()
127+
fig.savefig("../figures/advanced-hist.pdf")
136128

137129
# Xcorr plot
138130
# -----------------------------------------------------------------------------
131+
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
139132
np.random.seed(3)
140133
Y = np.random.uniform(-4, 4, 250)
141134
X = np.random.uniform(-4, 4, 250)
@@ -144,6 +137,5 @@
144137
ax.set_xlim(-8, 8), ax.set_xticks(np.arange(-8, 8, 2))
145138
ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9))
146139
ax.set_axisbelow(True)
147-
ax.grid(linewidth=0.125)
148-
plt.savefig("../figures/advanced-xcorr.pdf")
149-
ax.clear()
140+
ax.grid()
141+
fig.savefig("../figures/advanced-xcorr.pdf")

0 commit comments

Comments
 (0)