Skip to content

Commit 798ee83

Browse files
authored
Merge pull request #92 from timhoffm/formatting
Apply PEP-8 compatible code formatting
2 parents 5f45dcb + d098345 commit 798ee83

File tree

2 files changed

+94
-99
lines changed

2 files changed

+94
-99
lines changed

scripts/advanced-plots.py

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,57 @@
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
1010

11-
fig = plt.figure(figsize=(0.4,0.4))
11+
fig = plt.figure(figsize=(0.4, 0.4))
1212
mpl.rcParams['axes.linewidth'] = 0.5
1313
mpl.rcParams['xtick.major.size'] = 0.0
1414
mpl.rcParams['ytick.major.size'] = 0.0
1515
d = 0.01
16-
ax = fig.add_axes([d,d,1-2*d,1-2*d])
17-
16+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
1817

1918
# Step plot
2019
# -----------------------------------------------------------------------------
2120
X = np.linspace(0, 10, 16)
22-
Y = 4+2*np.sin(2*X)
21+
Y = 4 + 2*np.sin(2*X)
2322
ax.step(X, Y, color="C1", linewidth=0.75)
24-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
25-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
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))
2625
ax.grid(linewidth=0.125)
2726
plt.savefig("../figures/advanced-step.pdf")
2827
ax.clear()
2928

3029
# Violin plot
3130
# -----------------------------------------------------------------------------
3231
np.random.seed(10)
33-
D = np.random.normal((3,5,4), (0.75, 1.00, 0.75), (200,3))
34-
VP = ax.violinplot(D, [2,4,6], widths=1.5,
32+
D = np.random.normal((3, 5, 4), (0.75, 1.00, 0.75), (200, 3))
33+
VP = ax.violinplot(D, [2, 4, 6], widths=1.5,
3534
showmeans=False, showmedians=False, showextrema=False)
3635
for body in VP['bodies']:
3736
body.set_facecolor('C1')
3837
body.set_alpha(1)
39-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
40-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
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))
4140
ax.set_axisbelow(True)
4241
ax.grid(linewidth=0.125)
4342
plt.savefig("../figures/advanced-violin.pdf")
4443
ax.clear()
4544

46-
4745
# Boxplot
4846
# -----------------------------------------------------------------------------
4947
np.random.seed(10)
50-
D = np.random.normal((3,5,4), (1.25, 1.00, 1.25), (100,3))
51-
VP = ax.boxplot(D, positions=[2,4,6], widths=1.5, patch_artist=True,
48+
D = np.random.normal((3, 5, 4), (1.25, 1.00, 1.25), (100, 3))
49+
VP = ax.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True,
5250
showmeans=False, showfliers=False,
53-
medianprops = {"color": "white",
54-
"linewidth": 0.25},
55-
boxprops = {"facecolor": "C1",
56-
"edgecolor": "white",
57-
"linewidth": 0.25},
58-
whiskerprops = {"color": "C1",
59-
"linewidth": 0.75},
60-
capprops = {"color": "C1",
61-
"linewidth": 0.75})
62-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
63-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
51+
medianprops={"color": "white",
52+
"linewidth": 0.25},
53+
boxprops={"facecolor": "C1",
54+
"edgecolor": "white",
55+
"linewidth": 0.25},
56+
whiskerprops={"color": "C1",
57+
"linewidth": 0.75},
58+
capprops={"color": "C1",
59+
"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))
6462
ax.set_axisbelow(True)
6563
ax.grid(linewidth=0.125)
6664
plt.savefig("../figures/advanced-boxplot.pdf")
@@ -69,13 +67,13 @@
6967
# Barbs plot
7068
# -----------------------------------------------------------------------------
7169
np.random.seed(1)
72-
X = [[2,4,6]]
73-
Y = [[1.5,3,2]]
74-
U = -np.ones((1,3))*0
75-
V = -np.ones((1,3))*np.linspace(50,100,3)
76-
ax.barbs(X,Y,U,V, barbcolor="C1", flagcolor="C1", length=5, linewidth=0.5)
77-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
78-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
70+
X = [[2, 4, 6]]
71+
Y = [[1.5, 3, 2]]
72+
U = -np.ones((1, 3)) * 0
73+
V = -np.ones((1, 3)) * np.linspace(50, 100, 3)
74+
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))
7977
ax.set_axisbelow(True)
8078
ax.grid(linewidth=0.125)
8179
plt.savefig("../figures/advanced-barbs.pdf")
@@ -84,11 +82,12 @@
8482
# Event plot
8583
# -----------------------------------------------------------------------------
8684
np.random.seed(1)
87-
X = [2,4,6]
85+
X = [2, 4, 6]
8886
D = np.random.gamma(4, size=(3, 50))
89-
ax.eventplot(D, colors="C1", orientation="vertical", lineoffsets=X, linewidth=0.25)
90-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
91-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
87+
ax.eventplot(D, colors="C1", orientation="vertical", lineoffsets=X,
88+
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))
9291
ax.set_axisbelow(True)
9392
ax.grid(linewidth=0.125)
9493
plt.savefig("../figures/advanced-event.pdf")
@@ -97,28 +96,27 @@
9796
# Errorbar plot
9897
# -----------------------------------------------------------------------------
9998
np.random.seed(1)
100-
X = [2,4,6]
101-
Y = [4,5,4]
99+
X = [2, 4, 6]
100+
Y = [4, 5, 4]
102101
E = np.random.uniform(0.5, 1.5, 3)
103102
ax.errorbar(X, Y, E, color="C1", linewidth=0.75, capsize=1)
104-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
105-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
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))
106105
ax.set_axisbelow(True)
107106
ax.grid(linewidth=0.125)
108107
plt.savefig("../figures/advanced-errorbar.pdf")
109108
ax.clear()
110109

111-
112110
# Hexbin plot
113111
# -----------------------------------------------------------------------------
114112
np.random.seed(1)
115-
X = np.random.uniform(1.5,6.5,100)
116-
Y = np.random.uniform(1.5,6.5,100)
117-
C = np.random.uniform(0,1,10000)
113+
X = np.random.uniform(1.5, 6.5, 100)
114+
Y = np.random.uniform(1.5, 6.5, 100)
115+
C = np.random.uniform(0, 1, 10000)
118116
ax.hexbin(X, Y, C, gridsize=4, linewidth=0.25, edgecolor="white",
119117
cmap=plt.get_cmap("Wistia"), alpha=1.0)
120-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
121-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
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))
122120
ax.set_axisbelow(True)
123121
ax.grid(linewidth=0.125)
124122
plt.savefig("../figures/advanced-hexbin.pdf")
@@ -127,10 +125,10 @@
127125
# Hist plot
128126
# -----------------------------------------------------------------------------
129127
np.random.seed(1)
130-
X = 4 + np.random.normal(0,1.5,200)
131-
ax.hist(X, bins=8, facecolor="C1", linewidth=0.25, edgecolor="white",)
132-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
133-
ax.set_ylim(0, 80), ax.set_yticks(np.arange(1,80,10))
128+
X = 4 + np.random.normal(0, 1.5, 200)
129+
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))
131+
ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10))
134132
ax.set_axisbelow(True)
135133
ax.grid(linewidth=0.125)
136134
plt.savefig("../figures/advanced-hist.pdf")
@@ -143,8 +141,8 @@
143141
X = np.random.uniform(-4, 4, 250)
144142
ax.xcorr(X, Y, usevlines=True, maxlags=6, normed=True, lw=1,
145143
color="C1")
146-
ax.set_xlim(-8, 8), ax.set_xticks(np.arange(-8,8,2))
147-
ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25,.25,9))
144+
ax.set_xlim(-8, 8), ax.set_xticks(np.arange(-8, 8, 2))
145+
ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9))
148146
ax.set_axisbelow(True)
149147
ax.grid(linewidth=0.125)
150148
plt.savefig("../figures/advanced-xcorr.pdf")

scripts/basic-plots.py

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,45 @@
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
1010

11-
fig = plt.figure(figsize=(0.4,0.4))
11+
fig = plt.figure(figsize=(0.4, 0.4))
1212
mpl.rcParams['axes.linewidth'] = 0.5
1313
mpl.rcParams['xtick.major.size'] = 0.0
1414
mpl.rcParams['ytick.major.size'] = 0.0
1515
d = 0.01
16-
ax = fig.add_axes([d,d,1-2*d,1-2*d])
16+
ax = fig.add_axes([d, d, 1 - 2 * d, 1 - 2 * d])
1717

1818
# Basic line plot
1919
# -----------------------------------------------------------------------------
2020
X = np.linspace(0, 10, 100)
21-
Y = 4+2*np.sin(2*X)
21+
Y = 4 + 2*np.sin(2*X)
2222
ax.plot(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))
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))
2525
ax.grid(linewidth=0.125)
2626
plt.savefig("../figures/basic-plot.pdf")
2727
ax.clear()
2828

29+
# Basic line plot (color)blaPwd
2930

30-
# Basic line plot (color)
3131
# -----------------------------------------------------------------------------
3232
X = np.linspace(0, 10, 100)
33-
Y = 4+2*np.sin(2*X)
33+
Y = 4 + 2 * np.sin(2 * X)
3434
ax.plot(X, Y, color="black", linewidth=0.75)
35-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
36-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
35+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
36+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
3737
ax.grid(linewidth=0.125)
3838
plt.savefig("../figures/basic-plot-color.pdf")
3939
ax.clear()
4040

4141
# Basic scatter plot
4242
# -----------------------------------------------------------------------------
4343
np.random.seed(3)
44-
X = 4+np.random.normal(0, 1.25, 24)
45-
Y = 4+np.random.normal(0, 1.25, len(X))
44+
X = 4 + np.random.normal(0, 1.25, 24)
45+
Y = 4 + np.random.normal(0, 1.25, len(X))
4646
ax.scatter(X, Y, 5, zorder=10,
4747
edgecolor="white", facecolor="C1", linewidth=0.25)
48-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
49-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
48+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
49+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
5050
ax.grid(linewidth=0.125)
5151
plt.savefig("../figures/basic-scatter.pdf")
5252
ax.clear()
@@ -58,23 +58,22 @@
5858
Y = np.random.uniform(2, 7, len(X))
5959
ax.bar(X, Y, bottom=0, width=1,
6060
edgecolor="white", facecolor="C1", linewidth=0.25)
61-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
62-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
61+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
62+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
6363
ax.set_axisbelow(True)
6464
ax.grid(linewidth=0.125)
6565
plt.savefig("../figures/basic-bar.pdf")
6666
ax.clear()
6767

68-
6968
# Basic imshow plot
7069
# -----------------------------------------------------------------------------
7170
np.random.seed(3)
72-
I = np.zeros((8,8,4))
71+
I = np.zeros((8, 8, 4))
7372
I[:,:] = mpl.colors.to_rgba("C1")
74-
I[...,3] = np.random.uniform(0.25,1.0,(8,8))
75-
ax.imshow(I, extent=[0,8,0,8], interpolation="nearest")
76-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
77-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
73+
I[...,3] = np.random.uniform(0.25, 1.0, (8, 8))
74+
ax.imshow(I, extent=[0, 8, 0, 8], interpolation="nearest")
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))
7877
ax.grid(linewidth=0.25, color="white")
7978
plt.savefig("../figures/basic-imshow.pdf")
8079
ax.clear()
@@ -83,50 +82,48 @@
8382
# -----------------------------------------------------------------------------
8483
np.random.seed(1)
8584
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
86-
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
85+
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
8786
Z = Z - Z.min()
8887
plt.pcolormesh(X, Y, Z, cmap='Oranges', shading='auto')
8988
ax.set_xlim(-3, 3), ax.set_xticks(np.arange(-3, 4))
90-
ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3,4))
89+
ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3, 4))
9190
plt.savefig("../figures/basic-pcolormesh.pdf")
9291
ax.clear()
9392

9493
# Basic contour plot
9594
# -----------------------------------------------------------------------------
96-
colors = np.zeros((5,4))
95+
colors = np.zeros((5, 4))
9796
colors[:] = mpl.colors.to_rgba("C1")
98-
colors[:,3] = np.linspace(0.15, 0.85, len(colors))
99-
plt.contourf(Z, len(colors), extent=[0,8,0,8], colors=colors)
100-
plt.contour(Z, len(colors), extent=[0,8,0,8], colors="white", linewidths=0.125,
101-
nchunk=10)
102-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
103-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
97+
colors[:, 3] = np.linspace(0.15, 0.85, len(colors))
98+
plt.contourf(Z, len(colors), extent=[0, 8, 0, 8], colors=colors)
99+
plt.contour(Z, len(colors), extent=[0, 8, 0, 8], colors="white",
100+
linewidths=0.125, nchunk=10)
101+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
102+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
104103
plt.savefig("../figures/basic-contour.pdf")
105104
ax.clear()
106105

107-
108106
# Basic pie plot
109107
# -----------------------------------------------------------------------------
110-
X = 1,2,3,4
111-
colors = np.zeros((len(X),4))
108+
X = [1, 2, 3, 4]
109+
colors = np.zeros((len(X), 4))
112110
colors[:] = mpl.colors.to_rgba("C1")
113-
colors[:,3] = np.linspace(0.25, 0.75, len(X))
114-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
115-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
111+
colors[:, 3] = np.linspace(0.25, 0.75, len(X))
112+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
113+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
116114
ax.set_axisbelow(True)
117115
ax.grid(linewidth=0.25, color="0.75")
118-
ax.pie(X, colors=["white",]*len(X), radius=3, center=(4,4),
119-
wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True)
120-
ax.pie(X, colors=colors, radius=3, center=(4,4),
121-
wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True)
116+
ax.pie(X, colors=["white"] * len(X), radius=3, center=(4, 4),
117+
wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True)
118+
ax.pie(X, colors=colors, radius=3, center=(4, 4),
119+
wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True)
122120
plt.savefig("../figures/basic-pie.pdf")
123121
ax.clear()
124122

125-
126123
# Basic text plot
127124
# -----------------------------------------------------------------------------
128-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
129-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
125+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
126+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
130127
ax.set_axisbelow(True)
131128
ax.grid(linewidth=0.25, color="0.75")
132129
ax.text(4, 4, "TEXT", color="C1", size=8, weight="bold",
@@ -142,8 +139,8 @@
142139
Y2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X))
143140
plt.fill_between(X, Y1, Y2, color="C1", alpha=.5, linewidth=0)
144141
plt.plot(X, (Y1+Y2)/2, color="C1", linewidth=0.5)
145-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
146-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
142+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
143+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
147144
ax.set_axisbelow(True)
148145
ax.grid(linewidth=0.125, color="0.75")
149146
plt.savefig("../figures/basic-fill.pdf")
@@ -153,12 +150,12 @@
153150
# -----------------------------------------------------------------------------
154151
np.random.seed(1)
155152
T = np.linspace(0, 2*np.pi, 8)
156-
X, Y = 4 + 1*np.cos(T), 4 + 1*np.sin(T)
153+
X, Y = 4 + np.cos(T), 4 + np.sin(T)
157154
U, V = 1.5*np.cos(T), 1.5*np.sin(T)
158155
plt.quiver(X, Y, U, V, color="C1",
159156
angles='xy', scale_units='xy', scale=0.5, width=.05)
160-
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
161-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
157+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
158+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
162159
ax.set_axisbelow(True)
163160
ax.grid(linewidth=0.125, color="0.75")
164161
plt.savefig("../figures/basic-quiver.pdf")

0 commit comments

Comments
 (0)