Skip to content

Commit 7224cc5

Browse files
committed
refactor tips further
- replace calls to `plt` with `fig` or `ax` equivalents
1 parent fa241e2 commit 7224cc5

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

scripts/tips.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
colors = [cmap(i) for i in [0.1, 0.3, 0.5, 0.7]]
2828
ax.hist(X, 2, density=True, histtype='bar', color=colors)
2929

30-
plt.savefig("../figures/tip-color-range.pdf")
30+
fig.savefig("../figures/tip-color-range.pdf")
3131

3232

3333
# colorbar
@@ -42,7 +42,7 @@
4242
cb = fig.colorbar(im, fraction=0.046, pad=0.04)
4343
cb.set_ticks([])
4444

45-
plt.savefig("../figures/tip-colorbar.pdf")
45+
fig.savefig("../figures/tip-colorbar.pdf")
4646

4747

4848
# dotted
@@ -54,11 +54,11 @@
5454
)
5555

5656
epsilon=1e-12
57-
plt.plot([0,1], [0,0], "black", clip_on=False, lw=8,
57+
ax.plot([0,1], [0,0], "black", clip_on=False, lw=8,
5858
ls=(.5,(epsilon, 1)), dash_capstyle="round")
59-
plt.plot([0,1], [1,1], "black", clip_on=False, lw=8,
59+
ax.plot([0,1], [1,1], "black", clip_on=False, lw=8,
6060
ls=(-.5,(epsilon, 2)), dash_capstyle="round")
61-
plt.savefig("../figures/tip-dotted.pdf")
61+
fig.savefig("../figures/tip-dotted.pdf")
6262

6363

6464
# dual axis
@@ -79,7 +79,7 @@
7979
ax2.set_xticklabels([])
8080
ax2.set_yticklabels([])
8181

82-
plt.savefig("../figures/tip-dual-axis.pdf")
82+
fig.savefig("../figures/tip-dual-axis.pdf")
8383

8484

8585
# font family
@@ -121,17 +121,17 @@ def setup(ax):
121121
for tick in ax.get_xticklabels(which='both'):
122122
tick.set_fontname("Roboto Condensed")
123123

124-
plt.tight_layout()
125-
plt.savefig("../figures/tip-font-family.pdf", transparent=True)
124+
fig.tight_layout()
125+
fig.savefig("../figures/tip-font-family.pdf", transparent=True)
126126

127127

128128
# hatched
129129
# -----------------------------------------------------------------------------
130130
cmap = plt.get_cmap("Oranges")
131131
color1, color2 = cmap(0.3), cmap(0.5)
132132

133-
plt.rcParams['hatch.color'] = color1
134-
plt.rcParams['hatch.linewidth'] = 8
133+
mpl.rcParams['hatch.color'] = color1
134+
mpl.rcParams['hatch.linewidth'] = 8
135135

136136
fig = plt.figure(figsize=(2, 2))
137137
ax = plt.subplot()
@@ -142,13 +142,13 @@ def setup(ax):
142142

143143
ax.bar(x1, y1, color=color2)
144144
for i in range(len(x1)):
145-
plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0,1),
145+
ax.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0,1),
146146
fontsize="x-small", color=color2,
147147
textcoords="offset points", va="bottom", ha="center")
148148

149149
ax.bar(x2, y2, color=color2, hatch="/")
150150
for i in range(len(x2)):
151-
plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0,1),
151+
ax.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0,1),
152152
fontsize="x-small", color=color2,
153153
textcoords="offset points", va="bottom", ha="center")
154154

@@ -161,8 +161,8 @@ def setup(ax):
161161
ax.spines['left'].set_visible(False)
162162
ax.spines['top'].set_visible(False)
163163

164-
plt.tight_layout()
165-
plt.savefig("../figures/tip-hatched.pdf")
164+
fig.tight_layout()
165+
fig.savefig("../figures/tip-hatched.pdf")
166166

167167

168168
# multiline
@@ -175,12 +175,12 @@ def setup(ax):
175175
X.extend([x, x, None])
176176
Y.extend([0, np.sin(x), None])
177177
print(X[:10], Y[:10])
178-
plt.plot(X, Y, "black")
179-
plt.xticks([]), plt.yticks([])
180-
plt.xlim(-0.25, 10*np.pi+0.25)
181-
plt.ylim(-1.5, 1.5)
182-
plt.tight_layout()
183-
plt.savefig("../figures/tip-multiline.pdf", dpi=100)
178+
ax.plot(X, Y, "black")
179+
ax.set_xticks([]), ax.set_yticks([])
180+
ax.set_xlim(-0.25, 10*np.pi+0.25)
181+
ax.set_ylim(-1.5, 1.5)
182+
fig.tight_layout()
183+
fig.savefig("../figures/tip-multiline.pdf", dpi=100)
184184

185185

186186
# outline
@@ -197,7 +197,7 @@ def setup(ax):
197197
color=cmap(0.9), size=32, weight="bold", ha="center", va="bottom")
198198
text.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'),
199199
path_effects.Normal()])
200-
plt.savefig("../figures/tip-outline.pdf")
200+
fig.savefig("../figures/tip-outline.pdf")
201201

202202

203203
# transparency
@@ -214,4 +214,4 @@ def setup(ax):
214214

215215
ax.set_xlim([-1, 1]), ax.set_xticks([]),
216216
ax.set_ylim([-1, 1]), ax.set_yticks([])
217-
plt.savefig("../figures/tip-transparency.pdf")
217+
fig.savefig("../figures/tip-transparency.pdf")

0 commit comments

Comments
 (0)