8000 PEP8 moved examples · matplotlib/matplotlib@cc645b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc645b2

Browse files
committed
PEP8 moved examples
1 parent 8400147 commit cc645b2

23 files changed

+87
-77
lines changed

examples/event_handling/coords_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313

1414
t = np.arange(0.0, 1.0, 0.01)
15-
s = np.sin(2*np.pi*t)
15+
s = np.sin(2 * np.pi * t)
1616
fig, ax = plt.subplots()
1717
ax.plot(t, s)
1818

@@ -33,6 +33,7 @@ def on_click(event):
3333
if event.inaxes is not None:
3434
print('data coords %f %f' % (event.xdata, event.ydata))
3535

36+
3637
binding_id = plt.connect('motion_notify_event', on_move)
3738
plt.connect('button_press_event', on_click)
3839

examples/images_contours_and_fields/custom_cmap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
# Make some illustrative fake data:
7373

7474
x = np.arange(0, np.pi, 0.1)
75-
y = np.arange(0, 2*np.pi, 0.1)
75+
y = np.arange(0, 2 * np.pi, 0.1)
7676
X, Y = np.meshgrid(x, y)
7777
Z = np.cos(X) * np.sin(Y) * 10
7878

@@ -207,7 +207,7 @@
207207
#
208208

209209
# Draw a line with low zorder so it will be behind the image.
210-
axs[1, 1].plot([0, 10*np.pi], [0, 20*np.pi], color='c', lw=20, zorder=-1)
210+
axs[1, 1].plot([0, 10 * np.pi], [0, 20 * np.pi], color='c', lw=20, zorder=-1)
211211

212212
im4 = axs[1, 1].imshow(Z, interpolation='nearest')
213213
fig.colorbar(im4, ax=axs[1, 1])
@@ -219,5 +219,6 @@
219219
#
220220

221221
fig.suptitle('Custom Blue-Red colormaps', fontsize=16)
222+
fig.subplots_adjust(top=0.9)
222223

223224
plt.show()

examples/images_contours_and_fields/specgram_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414

1515
dt = 0.0005
1616
t = np.arange(0.0, 20.0, dt)
17-
s1 = np.sin(2*np.pi*100*t)
18-
s2 = 2*np.sin(2*np.pi*400*t)
17+
s1 = np.sin(2 * np.pi * 100 * t)
18+
s2 = 2 * np.sin(2 * np.pi * 400 * t)
1919

2020
# create a transient "chirp"
2121
mask = np.where(np.logical_and(t > 10, t < 12), 1.0, 0.0)
2222
s2 = s2 * mask
2323

2424
# add some noise into the mix
25-
nse = 0.01*np.random.random(size=len(t))
25+
nse = 0.01 * np.random.random(size=len(t))
2626

2727
x = s1 + s2 + nse # the signal
2828
NFFT = 1024 # the length of the windowing segments
29-
Fs = int(1.0/dt) # the sampling frequency
29+
Fs = int(1.0 / dt) # the sampling frequency
3030

3131
# Pxx is the segments x freqs array of instantaneous power, freqs is
3232
# the frequency vector, bins are the centers of the time bins in which

examples/lines_bars_and_markers/csd_demo.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
========
3-
Csd Demo
3+
CSD Demo
44
========
55
66
Compute the cross spectral density of two signals
@@ -22,21 +22,21 @@
2222

2323
nse1 = np.random.randn(len(t)) # white noise 1
2424
nse2 = np.random.randn(len(t)) # white noise 2
25-
r = np.exp(-t/0.05)
25+
r = np.exp(-t / 0.05)
2626

27-
cnse1 = np.convolve(nse1, r, mode='same')*dt # colored noise 1
28-
cnse2 = np.convolve(nse2, r, mode='same')*dt # colored noise 2
27+
cnse1 = np.convolve(nse1, r, mode='same') * dt # colored noise 1
28+
cnse2 = np.convolve(nse2, r, mode='same') * dt # colored noise 2
2929

3030
# two signals with a coherent part and a random part
31-
s1 = 0.01*np.sin(2*np.pi*10*t) + cnse1
32-
s2 = 0.01*np.sin(2*np.pi*10*t) + cnse2
31+
s1 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse1
32+
s2 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse2
3333

3434
ax1.plot(t, s1, t, s2)
3535
ax1.set_xlim(0, 5)
3636
ax1.set_xlabel('time')
3737
ax1.set_ylabel('s1 and s2')
3838
ax1.grid(True)
3939

40-
cxy, f = ax2.csd(s1, s2, 256, 1./dt)
40+
cxy, f = ax2.csd(s1, s2, 256, 1. / dt)
4141
ax2.set_ylabel('CSD (db)')
4242
plt.show()

examples/lines_bars_and_markers/errorbar_limits.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313

1414
fig = plt.figure(0)
1515
x = np.arange(10.0)
16-
y = np.sin(np.arange(10.0)/20.0*np.pi)
16+
y = np.sin(np.arange(10.0) / 20.0 * np.pi)
1717

1818
plt.errorbar(x, y, yerr=0.1)
1919

20-
y = np.sin(np.arange(10.0)/20.0*np.pi) + 1
20+
y = np.sin(np.arange(10.0) / 20.0 * np.pi) + 1
2121
plt.errorbar(x, y, yerr=0.1, uplims=True)
2222

23-
y = np.sin(np.arange(10.0)/20.0*np.pi) + 2
24-
upperlimits = np.array([1, 0]*5)
25-
lowerlimits = np.array([0, 1]*5)
23+
y = np.sin(np.arange(10.0) / 20.0 * np.pi) + 2
24+
upperlimits = np.array([1, 0] * 5)
25+
lowerlimits = np.array([0, 1] * 5)
2626
plt.errorbar(x, y, yerr=0.1, uplims=upperlimits, lolims=lowerlimits)
2727

2828
plt.xlim(-1, 10)
2929

3030
###############################################################################
3131

3232
fig = plt.figure(1)
33-
x = np.arange(10.0)/10.0
33+
x = np.arange(10.0) / 10.0
3434
y = (x + 0.1)**2
3535

3636
plt.errorbar(x, y, xerr=0.1, xlolims=True)

examples/lines_bars_and_markers/errorbar_subsample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
y = np.exp(-x)
1616

1717
# example variable error bar values
18-
yerr = 0.1 + 0.1*np.sqrt(x)
18+
yerr = 0.1 + 0.1 * np.sqrt(x)
1919

2020

2121
# Now switch to a more OO interface to exercise more features.

examples/lines_bars_and_markers/fill_between_demo.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import numpy as np
1212

1313
x = np.arange(0.0, 2, 0.01)
14-
y1 = np.sin(2*np.pi*x)
15-
y2 = 1.2*np.sin(4*np.pi*x)
14+
y1 = np.sin(2 * np.pi * x)
15+
y2 = 1.2 * np.sin(4 * np.pi * x)
1616

1717
###############################################################################
1818

@@ -43,8 +43,10 @@
4343
# Test support for masked arrays.
4444
y2 = np.ma.masked_greater(y2, 1.0)
4545
ax1.plot(x, y1, x, y2, color='black')
46-
ax1.fill_between(x, y1, y2, where=y2 >= y1, facecolor='green', interpolate=True)
47-
ax1.fill_between(x, y1, y2, where=y2 <= y1, facecolor='red', interpolate=True)
46+
ax1.fill_between(x, y1, y2, where=y2 >= y1,
47+
facecolor='green', interpolate=True)
48+
ax1.fill_between(x, y1, y2, where=y2 <= y1,
49+
facecolor='red', interpolate=True)
4850
ax1.set_title('Now regions with y2>1 are masked')
4951

5052
###############################################################################
@@ -58,7 +60,7 @@
5860
# Use transforms to create axes spans where a certain condition is satisfied:
5961

6062
fig, ax = plt.subplots()
61-
y = np.sin(4*np.pi*x)
63+
y = np.sin(4 * np.pi * x)
6264
ax.plot(x, y, color='black')
6365

6466
# use data coordinates for the x-axis and the axes coordinates for the y-axis
@@ -67,8 +69,10 @@
6769
theta = 0.9
6870
ax.axhline(theta, color='green', lw=2, alpha=0.5)
6971
ax.axhline(-theta, color='red', lw=2, alpha=0.5)
70-
ax.fill_between(x, 0, 1, where=y > theta, facecolor='green', alpha=0.5, transform=trans)
71-
ax.fill_between(x, 0, 1, where=y < -theta, facecolor='red', alpha=0.5, transform=trans)
72+
ax.fill_between(x, 0, 1, where=y > theta,
73+
facecolor='green', alpha=0.5, transform=trans)
74+
ax.fill_between(x, 0, 1, where=y < -theta,
75+
facecolor='red', alpha=0.5, transform=trans)
7276

7377

7478
plt.show()

examples/lines_bars_and_markers/fill_betweenx_demo.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
66
Using ``fill_betweenx`` to color between two horizontal curves.
77
"""
8-
import matplotlib.mlab as mlab
9-
from matplotlib.pyplot import figure, show
8+
import matplotlib.pyplot as plt
109
import numpy as np
1110

1211

1312
y = np.arange(0.0, 2, 0.01)
14-
x1 = np.sin(2*np.pi*y)
15-
x2 = 1.2*np.sin(4*np.pi*y)
13+
x1 = np.sin(2 * np.pi * y)
14+
x2 = 1.2 * np.sin(4 * np.pi * y)
1615

17-
fig = figure()
18-
ax1 = fig.add_subplot(311)
19-
ax2 = fig.add_subplot(312, sharex=ax1)
20-
ax3 = fig.add_subplot(313, sharex=ax1)
16+
fig, [ax1, ax2, ax3] = plt.subplots(3, 1, sharex=True)
2117

2218
ax1.fill_betweenx(y, 0, x1)
2319
ax1.set_ylabel('(x1, 0)')
@@ -34,16 +30,14 @@
3430
# fill_between(y[where], x1[where], x2[where])
3531
# because of edge effects over multiple contiguous regions.
3632

37-
fig = figure()
38-
ax = fig.add_subplot(211)
33+
fig, [ax, ax1] = plt.subplots(2, 1, sharex=True)
3934
ax.plot(x1, y, x2, y, color='black')
4035
ax.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green')
4136
ax.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red')
4237
ax.set_title('fill between where')
4338

4439
# Test support for masked arrays.
4540
x2 = np.ma.masked_greater(x2, 1.0)
46-
ax1 = fig.add_subplot(212, sharex=ax)
4741
ax1.plot(x1, y, x2, y, color='black')
4842
ax1.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green')
4943
ax1.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red')
@@ -54,4 +48,4 @@
5448
# points. A brute-force solution would be to interpolate all
5549
# arrays to a very fine grid before plotting.
5650

57-
show()
51+
plt.show()

examples/lines_bars_and_markers/gradient_bar.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
============
55
66
"""
7-
from matplotlib.pyplot import figure, show, cm
7+
import matplotlib.pyplot as plt
88
from numpy import arange
99
from numpy.random import rand
1010

@@ -13,23 +13,24 @@ def gbar(ax, x, y, width=0.5, bottom=0):
1313
X = [[.6, .6], [.7, .7]]
1414
for left, top in zip(x, y):
1515
right = left + width
16-
ax.imshow(X, interpolation='bicubic', cmap=cm.Blues,
16+
ax.imshow(X, interpolation='bicubic', cmap=plt.cm.Blues,
1717
extent=(left, right, bottom, top), alpha=1)
1818

19-
fig = figure()
19+
20+
fig = plt.figure()
2021

2122
xmin, xmax = xlim = 0, 10
2223
ymin, ymax = ylim = 0, 1
2324
ax = fig.add_subplot(111, xlim=xlim, ylim=ylim,
2425
autoscale_on=False)
2526
X = [[.6, .6], [.7, .7]]
2627

27-
ax.imshow(X, interpolation='bicubic', cmap=cm.copper,
28+
ax.imshow(X, interpolation='bicubic', cmap=plt.cm.copper,
2829
extent=(xmin, xmax, ymin, ymax), alpha=1)
2930

3031
N = 10
3132
x = arange(N) + 0.25
3233
y = rand(N)
3334
gbar(ax, x, y, width=0.7)
3435
ax.set_aspect('auto')
35-
show()
36+
plt.show()

examples/lines_bars_and_markers/psd_demo.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
dt = 0.01
2121
t = np.arange(0, 10, dt)
2222
nse = np.random.randn(len(t))
23-
r = np.exp(-t/0.05)
23+
r = np.exp(-t / 0.05)
2424

25-
cnse = np.convolve(nse, r)*dt
25+
cnse = np.convolve(nse, r) * dt
2626
cnse = cnse[:len(t)]
27-
s = 0.1*np.sin(2*np.pi*t) + cnse
27+
s = 0.1 * np.sin(2 * np.pi * t) + cnse
2828

2929
plt.subplot(211)
3030
plt.plot(t, s)
3131
plt.subplot(212)
32-
plt.psd(s, 512, 1/dt)
32+
plt.psd(s, 512, 1 / dt)
3333

3434
plt.show()
3535

@@ -68,24 +68,26 @@
6868
# time series at once
6969
ax2 = fig.add_subplot(2, 3, 4)
7070
ax2.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
71-
ax2.psd(y, NFFT=len(t), pad_to=len(t)*2, Fs=fs)
72-
ax2.psd(y, NFFT=len(t), pad_to=len(t)*4, Fs=fs)
71+
ax2.psd(y, NFFT=len(t), pad_to=len(t) * 2, Fs=fs)
72+
ax2.psd(y, NFFT=len(t), pad_to=len(t) * 4, Fs=fs)
7373
plt.title('zero padding')
7474

7575
# Plot the PSD with different block sizes, Zero pad to the length of the
7676
# original data sequence.
7777
ax3 = fig.add_subplot(2, 3, 5, sharex=ax2, sharey=ax2)
7878
ax3.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
79-
ax3.psd(y, NFFT=len(t)//2, pad_to=len(t), Fs=fs)
80-
ax3.psd(y, NFFT=len(t)//4, pad_to=len(t), Fs=fs)
79+
ax3.psd(y, NFFT=len(t) // 2, pad_to=len(t), Fs=fs)
80+
ax3.psd(y, NFFT=len(t) // 4, pad_to=len(t), Fs=fs)
8181
ax3.set_ylabel('')
8282
plt.title('block size')
8383

8484
# Plot the PSD with different amounts of overlap between blocks
8585
ax4 = fig.add_subplot(2, 3, 6, sharex=ax2, sharey=ax2)
86-
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=0, Fs=fs)
87-
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.05*len(t)/2.), Fs=fs)
88-
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.2*len(t)/2.), Fs=fs)
86+
ax4.psd(y, NFFT=len(t) // 2, pad_to=len(t), noverlap=0, Fs=fs)
87+
ax4.psd(y, NFFT=len(t) // 2, pad_to=len(t),
88+
noverlap=int(0.05 * len(t) / 2.), Fs=fs)
89+
ax4.psd(y, NFFT=len(t) // 2, pad_to=len(t),
90+
noverlap=int(0.2 * len(t) / 2.), Fs=fs)
8991
ax4.set_ylabel('')
9092
plt.title('overlap')
9193

examples/lines_bars_and_markers/spectrum_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
np.random.seed(0)
1515

1616
dt = 0.01 # sampling interval
17-
Fs = 1/dt # sampling frequency
17+
Fs = 1 / dt # sampling frequency
1818
t = np.arange(0, 10, dt)
1919

2020
# generate noise:
2121
nse = np.random.randn(len(t))
22-
r = np.exp(-t/0.05)
23-
cnse = np.convolve(nse, r)*dt
22+
r = np.exp(-t / 0.05)
23+
cnse = np.convolve(nse, r) * dt
2424
cnse = cnse[:len(t)]
2525

26-
s = 0.1*np.sin(4*np.pi*t) + cnse # the signal
26+
s = 0.1 * np.sin(4 * np.pi * t) + cnse # the signal
2727

2828
fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(7, 7))
2929

examples/lines_bars_and_markers/stackplot_demo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
def fnx():
2020
return np.random.randint(5, 50, 10)
2121

22+
2223
y = np.row_stack((fnx(), fnx(), fnx()))
2324
x = np.arange(10)
2425

@@ -53,6 +54,7 @@ def bump(a):
5354
bump(a[:, i])
5455
return a
5556

57+
5658
d = layers(3, 100)
5759

5860
fig, ax = plt.subplots()

examples/lines_bars_and_markers/stem_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11-
x = np.linspace(0.1, 2*np.pi, 10)
11+
x = np.linspace(0.1, 2 * np.pi, 10)
1212
markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')
1313
plt.setp(baseline, 'color', 'r', 'linewidth', 2)
1414

examples/shapes_and_collections/dolphin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
code_map = {
7878
'M': (Path.MOVETO, 1),
7979
'C': (Path.CURVE4, 3),
80-
'L': (Path.LINETO, 1)
81-
}
80+
'L': (Path.LINETO, 1)}
8281

8382
while i < len(parts):
8483
code = parts[i]

0 commit comments

Comments
 (0)
0