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

Skip to content

Commit 36c859e

Browse files
committed
PEP8 on tri* pylab_examples.
1 parent b0da7fe commit 36c859e

File tree

6 files changed

+149
-129
lines changed

6 files changed

+149
-129
lines changed

examples/pylab_examples/tricontour_demo.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
radii = np.linspace(min_radius, 0.95, n_radii)
1717

1818
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
19-
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
20-
angles[:,1::2] += math.pi/n_angles
19+
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
20+
angles[:, 1::2] += math.pi/n_angles
2121

2222
x = (radii*np.cos(angles)).flatten()
2323
y = (radii*np.sin(angles)).flatten()
@@ -46,47 +46,53 @@
4646
# anticlockwise manner.
4747

4848
xy = np.asarray([
49-
[-0.101,0.872],[-0.080,0.883],[-0.069,0.888],[-0.054,0.890],[-0.045,0.897],
50-
[-0.057,0.895],[-0.073,0.900],[-0.087,0.898],[-0.090,0.904],[-0.069,0.907],
51-
[-0.069,0.921],[-0.080,0.919],[-0.073,0.928],[-0.052,0.930],[-0.048,0.942],
52-
[-0.062,0.949],[-0.054,0.958],[-0.069,0.954],[-0.087,0.952],[-0.087,0.959],
53-
[-0.080,0.966],[-0.085,0.973],[-0.087,0.965],[-0.097,0.965],[-0.097,0.975],
54-
[-0.092,0.984],[-0.101,0.980],[-0.108,0.980],[-0.104,0.987],[-0.102,0.993],
55-
[-0.115,1.001],[-0.099,0.996],[-0.101,1.007],[-0.090,1.010],[-0.087,1.021],
56-
[-0.069,1.021],[-0.052,1.022],[-0.052,1.017],[-0.069,1.010],[-0.064,1.005],
57-
[-0.048,1.005],[-0.031,1.005],[-0.031,0.996],[-0.040,0.987],[-0.045,0.980],
58-
[-0.052,0.975],[-0.040,0.973],[-0.026,0.968],[-0.020,0.954],[-0.006,0.947],
59-
[ 0.003,0.935],[ 0.006,0.926],[ 0.005,0.921],[ 0.022,0.923],[ 0.033,0.912],
60-
[ 0.029,0.905],[ 0.017,0.900],[ 0.012,0.895],[ 0.027,0.893],[ 0.019,0.886],
61-
[ 0.001,0.883],[-0.012,0.884],[-0.029,0.883],[-0.038,0.879],[-0.057,0.881],
62-
[-0.062,0.876],[-0.078,0.876],[-0.087,0.872],[-0.030,0.907],[-0.007,0.905],
63-
[-0.057,0.916],[-0.025,0.933],[-0.077,0.990],[-0.059,0.993] ])
64-
x = xy[:,0]*180/3.14159
65-
y = xy[:,1]*180/3.14159
49+
[-0.101, 0.872], [-0.080, 0.883], [-0.069, 0.888], [-0.054, 0.890],
50+
[-0.045, 0.897], [-0.057, 0.895], [-0.073, 0.900], [-0.087, 0.898],
51+
[-0.090, 0.904], [-0.069, 0.907], [-0.069, 0.921], [-0.080, 0.919],
52+
[-0.073, 0.928], [-0.052, 0.930], [-0.048, 0.942], [-0.062, 0.949],
53+
[-0.054, 0.958], [-0.069, 0.954], [-0.087, 0.952], [-0.087, 0.959],
54+
[-0.080, 0.966], [-0.085, 0.973], [-0.087, 0.965], [-0.097, 0.965],
55+
[-0.097, 0.975], [-0.092, 0.984], [-0.101, 0.980], [-0.108, 0.980],
56+
[-0.104, 0.987], [-0.102, 0.993], [-0.115, 1.001], [-0.099, 0.996],
57+
[-0.101, 1.007], [-0.090, 1.010], [-0.087, 1.021], [-0.069, 1.021],
58+
[-0.052, 1.022], [-0.052, 1.017], [-0.069, 1.010], [-0.064, 1.005],
59+
[-0.048, 1.005], [-0.031, 1.005], [-0.031, 0.996], [-0.040, 0.987],
60+
[-0.045, 0.980], [-0.052, 0.975], [-0.040, 0.973], [-0.026, 0.968],
61+
[-0.020, 0.954], [-0.006, 0.947], [ 0.003, 0.935], [ 0.006, 0.926],
62+
[ 0.005, 0.921], [ 0.022, 0.923], [ 0.033, 0.912], [ 0.029, 0.905],
63+
[ 0.017, 0.900], [ 0.012, 0.895], [ 0.027, 0.893], [ 0.019, 0.886],
64+
[ 0.001, 0.883], [-0.012, 0.884], [-0.029, 0.883], [-0.038, 0.879],
65+
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
66+
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
67+
[-0.077, 0.990], [-0.059, 0.993]])
68+
x = xy[:, 0]*180/3.14159
69+
y = xy[:, 1]*180/3.14159
6670
x0 = -5
6771
y0 = 52
68-
z = np.exp(-0.01*( (x-x0)*(x-x0) + (y-y0)*(y-y0) ))
72+
z = np.exp(-0.01*((x-x0)*(x-x0) + (y-y0)*(y-y0)))
6973

7074
triangles = np.asarray([
71-
[67,66, 1],[65, 2,66],[ 1,66, 2],[64, 2,65],[63, 3,64],[60,59,57],
72-
[ 2,64, 3],[ 3,63, 4],[ 0,67, 1],[62, 4,63],[57,59,56],[59,58,56],
73-
[61,60,69],[57,69,60],[ 4,62,68],[ 6, 5, 9],[61,68,62],[69,68,61],
74-
[ 9, 5,70],[ 6, 8, 7],[ 4,70, 5],[ 8, 6, 9],[56,69,57],[69,56,52],
75-
[70,10, 9],[54,53,55],[56,55,53],[68,70, 4],[52,56,53],[11,10,12],
76-
[69,71,68],[68,13,70],[10,70,13],[51,50,52],[13,68,71],[52,71,69],
77-
[12,10,13],[71,52,50],[71,14,13],[50,49,71],[49,48,71],[14,16,15],
78-
[14,71,48],[17,19,18],[17,20,19],[48,16,14],[48,47,16],[47,46,16],
79-
[16,46,45],[23,22,24],[21,24,22],[17,16,45],[20,17,45],[21,25,24],
80-
[27,26,28],[20,72,21],[25,21,72],[45,72,20],[25,28,26],[44,73,45],
81-
[72,45,73],[28,25,29],[29,25,31],[43,73,44],[73,43,40],[72,73,39],
82-
[72,31,25],[42,40,43],[31,30,29],[39,73,40],[42,41,40],[72,33,31],
83-
[32,31,33],[39,38,72],[33,72,38],[33,38,34],[37,35,38],[34,38,35],
84-
[35,37,36] ])
75+
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],
76+
[60, 59, 57], [ 2, 64, 3], [ 3, 63, 4], [ 0, 67, 1], [62, 4, 63],
77+
[57, 59, 56], [59, 58, 56], [61, 60, 69], [57, 69, 60], [ 4, 62, 68],
78+
[ 6, 5, 9], [61, 68, 62], [69, 68, 61], [ 9, 5, 70], [ 6, 8, 7],
79+
[ 4, 70, 5], [ 8, 6, 9], [56, 69, 57], [69, 56, 52], [70, 10, 9],
80+
[54, 53, 55], [56, 55, 53], [68, 70, 4], [52, 56, 53], [11, 10, 12],
81+
[69, 71, 68], [68, 13, 70], [10, 70, 13], [51, 50, 52], [13, 68, 71],
82+
[52, 71, 69], [12, 10, 13], [71, 52, 50], [71, 14, 13], [50, 49, 71],
83+
[49, 48, 71], [14, 16, 15], [14, 71, 48], [17, 19, 18], [17, 20, 19],
84+
[48, 16, 14], [48, 47, 16], [47, 46, 16], [16, 46, 45], [23, 22, 24],
85+
[21, 24, 22], [17, 16, 45], [20, 17, 45], [21, 25, 24], [27, 26, 28],
86+
[20, 72, 21], [25, 21, 72], [45, 72, 20], [25, 28, 26], [44, 73, 45],
87+
[72, 45, 73], [28, 25, 29], [29, 25, 31], [43, 73, 44], [73, 43, 40],
88+
[72, 73, 39], [72, 31, 25], [42, 40, 43], [31, 30, 29], [39, 73, 40],
89+
[42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
90+
[33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
8591

8692
# Rather than create a Triangulation object, can simply pass x, y and triangles
87-
# arrays to tripcolor directly. It would be better to use a Triangulation object
88-
# if the same triangulation was to be used more than once to save duplicated
89-
# calculations.
93+
# arrays to tripcolor directly. It would be better to use a Triangulation
94+
# object if the same triangulation was to be used more than once to save
95+
# duplicated calculations.
9096
plt.figure()
9197
plt.gca().set_aspect('equal')
9298
plt.tricontourf(x, y, triangles, z)

examples/pylab_examples/tricontour_smooth_delaunay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def experiment_res(x, y):
9898
# Now the plots
9999
#-----------------------------------------------------------------------------
100100
# User options for plots
101-
plot_tri = True # plot of the base triangulation
102-
plot_masked_tri = True # plot of the excessively flat excluded triangles
103-
plot_refi_tri = False # plot of the refined triangulation
104-
plot_expected = False # plot of the analytical function values for comparison
101+
plot_tri = True # plot of base triangulation
102+
plot_masked_tri = True # plot of excessively flat excluded triangles
103+
plot_refi_tri = False # plot of refined triangulation
104+
plot_expected = False # plot of analytical function values for comparison
105105

106106

107107
# Graphical options for tricontouring

examples/pylab_examples/tricontour_smooth_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def function_z(x, y):
2424
return (np.max(z)-z)/(np.max(z)-np.min(z))
2525

2626
#-----------------------------------------------------------------------------
27-
# Creating a Triangulation
27+
# Creating a Triangulation
2828
#-----------------------------------------------------------------------------
2929
# First create the x and y coordinates of the points.
3030
n_angles = 20

examples/pylab_examples/tricontour_vs_griddata.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,45 @@
77
import numpy as np
88
from numpy.random import uniform, seed
99
from matplotlib.mlab import griddata
10+
from matplotlib.colors import Normalize
1011
import time
1112

1213
seed(0)
1314
npts = 200
1415
ngridx = 100
1516
ngridy = 200
16-
x = uniform(-2,2,npts)
17-
y = uniform(-2,2,npts)
18-
z = x*np.exp(-x**2-y**2)
17+
x = uniform(-2, 2, npts)
18+
y = uniform(-2, 2, npts)
19+
z = x*np.exp(-x**2 - y**2)
1920

2021
# griddata and contour.
2122
start = time.clock()
2223
plt.subplot(211)
23-
xi = np.linspace(-2.1,2.1,ngridx)
24-
yi = np.linspace(-2.1,2.1,ngridy)
25-
zi = griddata(x,y,z,xi,yi,interp='linear')
26-
plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k')
27-
plt.contourf(xi,yi,zi,15,cmap=plt.cm.rainbow,
28-
norm=plt.normalize(vmax=abs(zi).max(), vmin=-abs(zi).max()))
29-
plt.colorbar() # draw colorbar
24+
xi = np.linspace(-2.1, 2.1, ngridx)
25+
yi = np.linspace(-2.1, 2.1, ngridy)
26+
zi = griddata(x, y, z, xi, yi, interp='linear')
27+
plt.contour(xi, yi, zi, 15, linewidths=0.5, colors='k')
28+
plt.contourf(xi, yi, zi, 15, cmap=plt.cm.rainbow,
29+
norm=Normalize(vmax=abs(zi).max(), vmin=-abs(zi).max()))
30+
plt.colorbar() # draw colorbar
3031
plt.plot(x, y, 'ko', ms=3)
31-
plt.xlim(-2,2)
32-
plt.ylim(-2,2)
33-
plt.title('griddata and contour (%d points, %d grid points)' % (npts, ngridx*ngridy))
32+
plt.xlim(-2, 2)
33+
plt.ylim(-2, 2)
34+
plt.title('griddata and contour (%d points, %d grid points)' %
35+
(npts, ngridx*ngridy))
3436
print ('griddata and contour seconds: %f' % (time.clock() - start))
3537

3638
# tricontour.
3739
start = time.clock()
3840
plt.subplot(212)
3941
triang = tri.Triangulation(x, y)
4042
plt.tricontour(x, y, z, 15, linewidths=0.5, colors='k')
41-
plt.tricontourf(x, y, z, 15, cmap=plt.cm.rainbow,
42-
norm=plt.normalize(vmax=abs(zi).max(), vmin=-abs(zi).max()))
43+
plt.tricontourf(x, y, z, 15, cmap=plt.cm.rainbow,
44+
norm=Normalize(vmax=abs(zi).max(), vmin=-abs(zi).max()))
4345
plt.colorbar()
4446
plt.plot(x, y, 'ko', ms=3)
45-
plt.xlim(-2,2)
46-
plt.ylim(-2,2)
47+
plt.xlim(-2, 2)
48+
plt.ylim(-2, 2)
4749
plt.title('tricontour (%d points)' % npts)
4850
print ('tricontour seconds: %f' % (time.clock() - start))
4951

examples/pylab_examples/tripcolor_demo.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
radii = np.linspace(min_radius, 0.95, n_radii)
1717

1818
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
19-
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
20-
angles[:,1::2] += math.pi/n_angles
19+
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
20+
angles[:, 1::2] += math.pi/n_angles
2121

2222
x = (radii*np.cos(angles)).flatten()
2323
y = (radii*np.sin(angles)).flatten()
@@ -53,50 +53,56 @@
5353
# anticlockwise manner.
5454

5555
xy = np.asarray([
56-
[-0.101,0.872],[-0.080,0.883],[-0.069,0.888],[-0.054,0.890],[-0.045,0.897],
57-
[-0.057,0.895],[-0.073,0.900],[-0.087,0.898],[-0.090,0.904],[-0.069,0.907],
58-
[-0.069,0.921],[-0.080,0.919],[-0.073,0.928],[-0.052,0.930],[-0.048,0.942],
59-
[-0.062,0.949],[-0.054,0.958],[-0.069,0.954],[-0.087,0.952],[-0.087,0.959],
60-
[-0.080,0.966],[-0.085,0.973],[-0.087,0.965],[-0.097,0.965],[-0.097,0.975],
61-
[-0.092,0.984],[-0.101,0.980],[-0.108,0.980],[-0.104,0.987],[-0.102,0.993],
62-
[-0.115,1.001],[-0.099,0.996],[-0.101,1.007],[-0.090,1.010],[-0.087,1.021],
63-
[-0.069,1.021],[-0.052,1.022],[-0.052,1.017],[-0.069,1.010],[-0.064,1.005],
64-
[-0.048,1.005],[-0.031,1.005],[-0.031,0.996],[-0.040,0.987],[-0.045,0.980],
65-
[-0.052,0.975],[-0.040,0.973],[-0.026,0.968],[-0.020,0.954],[-0.006,0.947],
66-
[ 0.003,0.935],[ 0.006,0.926],[ 0.005,0.921],[ 0.022,0.923],[ 0.033,0.912],
67-
[ 0.029,0.905],[ 0.017,0.900],[ 0.012,0.895],[ 0.027,0.893],[ 0.019,0.886],
68-
[ 0.001,0.883],[-0.012,0.884],[-0.029,0.883],[-0.038,0.879],[-0.057,0.881],
69-
[-0.062,0.876],[-0.078,0.876],[-0.087,0.872],[-0.030,0.907],[-0.007,0.905],
70-
[-0.057,0.916],[-0.025,0.933],[-0.077,0.990],[-0.059,0.993] ])
71-
x = xy[:,0]*180/3.14159
72-
y = xy[:,1]*180/3.14159
56+
[-0.101, 0.872], [-0.080, 0.883], [-0.069, 0.888], [-0.054, 0.890],
57+
[-0.045, 0.897], [-0.057, 0.895], [-0.073, 0.900], [-0.087, 0.898],
58+
[-0.090, 0.904], [-0.069, 0.907], [-0.069, 0.921], [-0.080, 0.919],
59+
[-0.073, 0.928], [-0.052, 0.930], [-0.048, 0.942], [-0.062, 0.949],
60+
[-0.054, 0.958], [-0.069, 0.954], [-0.087, 0.952], [-0.087, 0.959],
61+
[-0.080, 0.966], [-0.085, 0.973], [-0.087, 0.965], [-0.097, 0.965],
62+
[-0.097, 0.975], [-0.092, 0.984], [-0.101, 0.980], [-0.108, 0.980],
63+
[-0.104, 0.987], [-0.102, 0.993], [-0.115, 1.001], [-0.099, 0.996],
64+
[-0.101, 1.007], [-0.090, 1.010], [-0.087, 1.021], [-0.069, 1.021],
65+
[-0.052, 1.022], [-0.052, 1.017], [-0.069, 1.010], [-0.064, 1.005],
66+
[-0.048, 1.005], [-0.031, 1.005], [-0.031, 0.996], [-0.040, 0.987],
67+
[-0.045, 0.980], [-0.052, 0.975], [-0.040, 0.973], [-0.026, 0.968],
68+
[-0.020, 0.954], [-0.006, 0.947], [ 0.003, 0.935], [ 0.006, 0.926],
69+
[ 0.005, 0.921], [ 0.022, 0.923], [ 0.033, 0.912], [ 0.029, 0.905],
70+
[ 0.017, 0.900], [ 0.012, 0.895], [ 0.027, 0.893], [ 0.019, 0.886],
71+
[ 0.001, 0.883], [-0.012, 0.884], [-0.029, 0.883], [-0.038, 0.879],
72+
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
73+
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
74+
[-0.077, 0.990], [-0.059, 0.993]])
75+
x = xy[:, 0]*180/3.14159
76+
y = xy[:, 1]*180/3.14159
7377

7478
triangles = np.asarray([
75-
[67,66, 1],[65, 2,66],[ 1,66, 2],[64, 2,65],[63, 3,64],[60,59,57],
76-
[ 2,64, 3],[ 3,63, 4],[ 0,67, 1],[62, 4,63],[57,59,56],[59,58,56],
77-
[61,60,69],[57,69,60],[ 4,62,68],[ 6, 5, 9],[61,68,62],[69,68,61],
78-
[ 9, 5,70],[ 6, 8, 7],[ 4,70, 5],[ 8, 6, 9],[56,69,57],[69,56,52],
79-
[70,10, 9],[54,53,55],[56,55,53],[68,70, 4],[52,56,53],[11,10,12],
80-
[69,71,68],[68,13,70],[10,70,13],[51,50,52],[13,68,71],[52,71,69],
81-
[12,10,13],[71,52,50],[71,14,13],[50,49,71],[49,48,71],[14,16,15],
82-
[14,71,48],[17,19,18],[17,20,19],[48,16,14],[48,47,16],[47,46,16],
83-
[16,46,45],[23,22,24],[21,24,22],[17,16,45],[20,17,45],[21,25,24],
84-
[27,26,28],[20,72,21],[25,21,72],[45,72,20],[25,28,26],[44,73,45],
85-
[72,45,73],[28,25,29],[29,25,31],[43,73,44],[73,43,40],[72,73,39],
86-
[72,31,25],[42,40,43],[31,30,29],[39,73,40],[42,41,40],[72,33,31],
87-
[32,31,33],[39,38,72],[33,72,38],[33,38,34],[37,35,38],[34,38,35],
88-
[35,37,36] ])
79+
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],
80+
[60, 59, 57], [ 2, 64, 3], [ 3, 63, 4], [ 0, 67, 1], [62, 4, 63],
81+
[57, 59, 56], [59, 58, 56], [61, 60, 69], [57, 69, 60], [ 4, 62, 68],
82+
[ 6, 5, 9], [61, 68, 62], [69, 68, 61], [ 9, 5, 70], [ 6, 8, 7],
83+
[ 4, 70, 5], [ 8, 6, 9], [56, 69, 57], [69, 56, 52], [70, 10, 9],
84+
[54, 53, 55], [56, 55, 53], [68, 70, 4], [52, 56, 53], [11, 10, 12],
85+
[69, 71, 68], [68, 13, 70], [10, 70, 13], [51, 50, 52], [13, 68, 71],
86+
[52, 71, 69], [12, 10, 13], [71, 52, 50], [71, 14, 13], [50, 49, 71],
87+
[49, 48, 71], [14, 16, 15], [14, 71, 48], [17, 19, 18], [17, 20, 19],
88+
[48, 16, 14], [48, 47, 16], [47, 46, 16], [16, 46, 45], [23, 22, 24],
89+
[21, 24, 22], [17, 16, 45], [20, 17, 45], [21, 25, 24], [27, 26, 28],
90+
[20, 72, 21], [25, 21, 72], [45, 72, 20], [25, 28, 26], [44, 73, 45],
91+
[72, 45, 73], [28, 25, 29], [29, 25, 31], [43, 73, 44], [73, 43, 40],
92+
[72, 73, 39], [72, 31, 25], [42, 40, 43], [31, 30, 29], [39, 73, 40],
93+
[42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
94+
[33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
8995

9096
xmid = x[triangles].mean(axis=1)
9197
ymid = y[triangles].mean(axis=1)
9298
x0 = -5
9399
y0 = 52
94-
zfaces = np.exp(-0.01*( (xmid-x0)*(xmid-x0) + (ymid-y0)*(ymid-y0) ))
100+
zfaces = np.exp(-0.01*((xmid-x0)*(xmid-x0) + (ymid-y0)*(ymid-y0)))
95101

96102
# Rather than create a Triangulation object, can simply pass x, y and triangles
97-
# arrays to tripcolor directly. It would be better to use a Triangulation object
98-
# if the same triangulation was to be used more than once to save duplicated
99-
# calculations.
103+
# arrays to tripcolor directly. It would be better to use a Triangulation
104+
# object if the same triangulation was to be used more than once to save
105+
#duplicated calculations.
100106
# Can specify one color value per face rather than one per point by using the
101107
# facecolors kwarg.
102108
plt.figure()

0 commit comments

Comments
 (0)