Skip to content

Commit 97a5b90

Browse files
committed
refactor tips
1 parent 106b95b commit 97a5b90

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

scripts/tips.py

+19-28
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
import numpy as np
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
10-
import matplotlib.ticker as ticker
1110
import matplotlib.patheffects as path_effects
1211

1312

13+
mpl.rcParams['axes.linewidth'] = 1.5
14+
15+
margin = 0.01
16+
rect = [margin, margin, 1-2*margin, 1-2*margin]
17+
18+
1419
# color range
1520
# -----------------------------------------------------------------------------
1621
fig = plt.figure(figsize=(2,2))
17-
mpl.rcParams['axes.linewidth'] = 1.5
18-
d = 0.01
19-
20-
ax = fig.add_axes([d,d,1-2*d,1-2*d], xticks=[], yticks=[])
22+
ax = fig.add_axes(rect, xticks=[], yticks=[])
2123

2224
X = np.random.seed(1)
2325
X = np.random.randn(1000, 4)
@@ -31,9 +33,7 @@
3133
# colorbar
3234
# -----------------------------------------------------------------------------
3335
fig = plt.figure(figsize=(2.15,2))
34-
mpl.rcParams['axes.linewidth'] = 1.5
35-
d = 0.01
36-
ax = fig.add_axes([d,d,1-2*d,1-2*d], xticks=[], yticks=[])
36+
ax = fig.add_axes(rect, xticks=[], yticks=[])
3737

3838
np.random.seed(1)
3939
Z = np.random.uniform(0,1,(8,8))
@@ -62,13 +62,9 @@
6262

6363
# dual axis
6464
# -----------------------------------------------------------------------------
65-
mpl.rcParams['axes.linewidth'] = 1.5
66-
67-
6865
fig = plt.figure(figsize=(2,2))
69-
d = 0.01
70-
ax1 = fig.add_axes([d,d,1-2*d,1-2*d], label="cartesian")
71-
ax2 = fig.add_axes([d,d,1-2*d,1-2*d], projection="polar", label="polar")
66+
ax1 = fig.add_axes(rect, label="cartesian")
67+
ax2 = fig.add_axes(rect, projection="polar", label="polar")
7268

7369
ax1.set_xticks([]) #np.linspace(0.0, 0.4, 5))
7470
ax1.set_yticks([]) #np.linspace(0.0, 1.0, 11))
@@ -91,9 +87,10 @@
9187
def setup(ax):
9288
ax.spines['right'].set_color('none')
9389
ax.spines['left'].set_color('none')
94-
ax.yaxis.set_major_locator(ticker.NullLocator())
90+
ax.yaxis.set_major_locator(mpl.ticker.NullLocator())
9591
ax.spines['top'].set_color('none')
9692

93+
ax.spines['bottom'].set_linewidth(1)
9794
ax.spines['bottom'].set_position("center")
9895

9996
ax.xaxis.set_ticks_position('bottom')
@@ -114,10 +111,10 @@ def setup(ax):
114111
ax = plt.subplot(n, 1, 1)
115112
ax.tick_params(axis='both', which='minor', labelsize=6)
116113
setup(ax)
117-
ax.xaxis.set_major_locator(ticker.MultipleLocator(1.0))
118-
ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.2))
119-
ax.xaxis.set_major_formatter(ticker.ScalarFormatter())
120-
ax.xaxis.set_minor_formatter(ticker.ScalarFormatter())
114+
ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1.0))
115+
ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.2))
116+
ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
117+
ax.xaxis.set_minor_formatter(mpl.ticker.ScalarFormatter())
121118
ax.tick_params(axis='x', which='minor', rotation=0)
122119

123120
for tick in ax.get_xticklabels(which='both'):
@@ -169,8 +166,6 @@ def setup(ax):
169166

170167
# multiline
171168
# -----------------------------------------------------------------------------
172-
mpl.rcParams['axes.linewidth'] = 1.5
173-
174169
fig = plt.figure(figsize=(8,1.5))
175170
dx,dy = 0.0025, 0.01
176171
ax = fig.add_axes([dx, dy, 1-2*dx, 1-2*dy], frameon=False)
@@ -190,10 +185,8 @@ def setup(ax):
190185
# outline
191186
# -----------------------------------------------------------------------------
192187
fig = plt.figure(figsize=(2,2))
193-
mpl.rcParams['axes.linewidth'] = 1.5
194-
d = 0.01
195188

196-
ax = fig.add_axes([d,d,1-2*d,1-2*d], xticks=[], yticks=[])
189+
ax = fig.add_axes(rect, xticks=[], yticks=[])
197190

198191
np.random.seed(1)
199192
Z = np.random.uniform(0,1,(8,8))
@@ -209,12 +202,10 @@ def setup(ax):
209202

210203
# transparency
211204
# -----------------------------------------------------------------------------
212-
mpl.rc('axes', linewidth=1.5)
213-
214205
fig = plt.figure(figsize=(2, 2), dpi=100)
215-
margin = 0.01
216-
ax = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin])
206+
ax = fig.add_axes(rect)
217207
n = 500
208+
np.random.seed(5)
218209
X = np.random.normal(0, 0.25, n)
219210
Y = np.random.normal(0, 0.25, n)
220211
ax.scatter(X, Y, s=50, c="k", lw=2)

0 commit comments

Comments
 (0)