Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d70af4c

Browse files
committed
Move some pylab examples to other folders
PEP8 moved examples Move subplots and scatter examples PEP8 scatter examples Small example fixes Remove old barchart demos Add new barchart demo back
1 parent 8ae0dbf commit d70af4c

19 files changed

+38
-50
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""
2-
===============
3-
Color By Yvalue
4-
===============
2+
================
3+
Color By y-value
4+
================
55
66
Use masked arrays to plot a line with different colors by y-value.
77
"""
88
import numpy as np
99
import matplotlib.pyplot as plt
1010

1111
t = np.arange(0.0, 2.0, 0.01)
12-
s = np.sin(2*np.pi*t)
12+
s = np.sin(2 * np.pi * t)
1313

1414
upper = 0.77
1515
lower = -0.77
@@ -19,5 +19,6 @@
1919
slower = np.ma.masked_where(s > lower, s)
2020
smiddle = np.ma.masked_where(np.logical_or(s < lower, s > upper), s)
2121

22-
plt.plot(t, smiddle, t, slower, t, supper)
22+
fig, ax = plt.subplots()
23+
ax.plot(t, smiddle, t, slower, t, supper)
2324
plt.show()

examples/pylab_examples/color_demo.py renamed to examples/color/color_demo.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
import matplotlib.pyplot as plt
2323
import numpy as np
2424

25-
plt.subplot(111, facecolor='darkslategray')
26-
#subplot(111, facecolor='#ababab')
2725
t = np.arange(0.0, 2.0, 0.01)
28-
s = np.sin(2*np.pi*t)
29-
plt.plot(t, s, 'C1')
30-
plt.xlabel('time (s)', color='C1')
31-
plt.ylabel('voltage (mV)', color='0.5') # grayscale color
32-
plt.title('About as silly as it gets, folks', color='#afeeee')
26+
s = np.sin(2 * np.pi * t)
27+
28+
fig, ax = plt.subplots(facecolor='darkslategray')
29+
ax.plot(t, s, 'C1')
30+
ax.set_xlabel('time (s)', color='C1')
31+
ax.set_ylabel('voltage (mV)', color='0.5') # grayscale color
32+
ax.set_title('About as silly as it gets, folks', color='#afeeee')
33+
3334
plt.show()

examples/pylab_examples/contour_corner_mask.py renamed to examples/images_contours_and_fields/contour_corner_mask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Data to plot.
1313
x, y = np.meshgrid(np.arange(7), np.arange(10))
14-
z = np.sin(0.5*x)*np.cos(0.52*y)
14+
z = np.sin(0.5 * x) * np.cos(0.52 * y)
1515

1616
# Mask various z values.
1717
mask = np.zeros_like(z, dtype=np.bool)
@@ -24,7 +24,7 @@
2424

2525
corner_masks = [False, True]
2626
for i, corner_mask in enumerate(corner_masks):
27-
plt.subplot(1, 2, i+1)
27+
plt.subplot(1, 2, i + 1)
2828
cs = plt.contourf(x, y, z, corner_mask=corner_mask)
2929
plt.contour(cs, colors='k')
3030
plt.title('corner_mask = {0}'.format(corner_mask))

examples/pylab_examples/scatter_custom_symbol.py renamed to examples/lines_bars_and_markers/scatter_custom_symbol.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
66
"""
77
import matplotlib.pyplot as plt
8-
from numpy import arange, pi, cos, sin
9-
from numpy.random import rand
8+
import numpy as np
109

1110
# unit area ellipse
1211
rx, ry = 3., 1.
13-
area = rx * ry * pi
14-
theta = arange(0, 2*pi + 0.01, 0.1)
15-
verts = list(zip(rx/area*cos(theta), ry/area*sin(theta)))
12+
area = rx * ry * np.pi
13+
theta = np.arange(0, 2 * np.pi + 0.01, 0.1)
14+
verts = list(zip(rx / area * np.cos(theta), ry / area * np.sin(theta)))
1615

17-
x, y, s, c = rand(4, 30)
16+
x, y, s, c = np.random.rand(4, 30)
1817
s *= 10**2.
1918

2019
fig, ax = plt.subplots()

examples/pylab_examples/scatter_demo2.py renamed to examples/lines_bars_and_markers/scatter_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
price_data = np.load(datafile)['price_data'].view(np.recarray)
1717
price_data = price_data[-250:] # get the most recent 250 trading days
1818

19-
delta1 = np.diff(price_data.adj_close)/price_data.adj_close[:-1]
19+
delta1 = np.diff(price_data.adj_close) / price_data.adj_close[:-1]
2020

2121
# Marker size in units of points^2
2222
volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2

examples/pylab_examples/scatter_masked.py renamed to examples/lines_bars_and_markers/scatter_masked.py

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

1414
N = 100
1515
r0 = 0.6
16-
x = 0.9*np.random.rand(N)
17-
y = 0.9*np.random.rand(N)
18-
area = np.pi*(10 * np.random.rand(N))**2 # 0 to 10 point radii
16+
x = 0.9 * np.random.rand(N)
17+
y = 0.9 * np.random.rand(N)
18+
area = np.pi * (10 * np.random.rand(N))**2 # 0 to 10 point radii
1919
c = np.sqrt(area)
20-
r = np.sqrt(x*x + y*y)
20+
r = np.sqrt(x * x + y * y)
2121
area1 = np.ma.masked_where(r < r0, area)
2222
area2 = np.ma.masked_where(r >= r0, area)
2323
plt.scatter(x, y, s=area1, marker='^', c=c)
2424
plt.scatter(x, y, s=area2, marker='o', c=c)
2525
# Show the boundary between the regions:
26-
theta = np.arange(0, np.pi/2, 0.01)
27-
plt.plot(r0*np.cos(theta), r0*np.sin(theta))
26+
theta = np.arange(0, np.pi / 2, 0.01)
27+
plt.plot(r0 * np.cos(theta), r0 * np.sin(theta))
2828

2929
plt.show()

examples/pylab_examples/scatter_profile.py renamed to examples/lines_bars_and_markers/scatter_profile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
for N in (20, 100, 1000, 10000, 50000):
3131
tstart = time.time()
32-
x = 0.9*np.random.rand(N)
33-
y = 0.9*np.random.rand(N)
34-
s = 20*np.random.rand(N)
32+
x = 0.9 * np.random.rand(N)
33+
y = 0.9 * np.random.rand(N)
34+
s = 20 * np.random.rand(N)
3535
plt.scatter(x, y, s)
3636
print('%d symbols in %1.2f s' % (N, time.time() - tstart))

examples/pylab_examples/scatter_star_poly.py renamed to examples/lines_bars_and_markers/scatter_star_poly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
plt.subplot(323)
2626
plt.scatter(x, y, s=80, c=z, marker=(verts, 0))
2727
# equivalent:
28-
#plt.scatter(x,y,s=80, c=z, marker=None, verts=verts)
28+
# plt.scatter(x, y, s=80, c=z, marker=None, verts=verts)
2929

3030
plt.subplot(324)
3131
plt.scatter(x, y, s=80, c=z, marker=(5, 1))

examples/pylab_examples/README

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/pylab_examples/barb_demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
x = np.linspace(-5, 5, 5)
1212
X, Y = np.meshgrid(x, x)
13-
U, V = 12*X, 12*Y
13+
U, V = 12 * X, 12 * Y
1414

1515
data = [(-1.5, .5, -6, -6),
1616
(1, -1, -46, 46),
@@ -27,29 +27,29 @@
2727
ax.barbs(X, Y, U, V)
2828

2929
# Arbitrary set of vectors, make them longer and change the pivot point
30-
#(point around which they're rotated) to be the middle
30+
# (point around which they're rotated) to be the middle
3131
ax = plt.subplot(2, 2, 2)
3232
ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')
3333

3434
# Showing colormapping with uniform grid. Fill the circle for an empty barb,
3535
# don't round the values, and change some of the size parameters
3636
ax = plt.subplot(2, 2, 3)
37-
ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False,
37+
ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
3838
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
3939

4040
# Change colors as well as the increments for parts of the barbs
4141
ax = plt.subplot(2, 2, 4)
4242
ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
43-
barbcolor=['b', 'g'], barb_increments=dict(half=10, full=20, flag=100),
44-
flip_barb=True)
43+
barbcolor=['b', 'g'],
44+
barb_increments=dict(half=10, full=20, flag=100), flip_barb=True)
4545

4646
# Masked arrays are also supported
4747
masked_u = np.ma.masked_array(data['u'])
4848
masked_u[4] = 1000 # Bad value that should not be plotted when masked
4949
masked_u[4] = np.ma.masked
5050

5151
# Identical plot to panel 2 in the first figure, but with the point at
52-
#(0.5, 0.25) missing (masked)
52+
# (0.5, 0.25) missing (masked)
5353
fig2 = plt.figure()
5454
ax = fig2.add_subplot(1, 1, 1)
5555
ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')

0 commit comments

Comments
 (0)