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

Lines changed: 38 additions & 50 deletions
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()
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))
File renamed without changes.

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
File renamed without changes.

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()

0 commit comments

Comments
 (0)