Skip to content

Commit b0da7fe

Browse files
committed
PEP8 on tri module source code.
1 parent 48b6c13 commit b0da7fe

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

lib/matplotlib/tri/triangulation.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ def __init__(self, x, y, triangles=None, mask=None):
5454
# No triangulation specified, so use matplotlib.delaunay.
5555
dt = delaunay.Triangulation(self.x, self.y)
5656
self.triangles = np.asarray(
57-
dt.to_client_point_indices(dt.triangle_nodes),
58-
dtype=np.int32)
57+
dt.to_client_point_indices(dt.triangle_nodes), dtype=np.int32)
5958
if mask is None:
6059
self._edges = np.asarray(
61-
dt.to_client_point_indices(dt.edge_db),
62-
dtype=np.int32)
60+
dt.to_client_point_indices(dt.edge_db), dtype=np.int32)
6361
# Delaunay triangle_neighbors uses different edge indexing,
6462
# so convert.
6563
neighbors = np.asarray(dt.triangle_neighbors, dtype=np.int32)
@@ -77,8 +75,8 @@ def __init__(self, x, y, triangles=None, mask=None):
7775

7876
if mask is not None:
7977
self.mask = np.asarray(mask, dtype=np.bool)
80-
if len(self.mask.shape) != 1 or \
81-
self.mask.shape[0] != self.triangles.shape[0]:
78+
if (len(self.mask.shape) != 1 or
79+
self.mask.shape[0] != self.triangles.shape[0]):
8280
raise ValueError('mask array must have same length as '
8381
'triangles array')
8482

@@ -195,8 +193,8 @@ def set_mask(self, mask):
195193
self.mask = None
196194
else:
197195
self.mask = np.asarray(mask, dtype=np.bool)
198-
if len(self.mask.shape) != 1 or \
199-
self.mask.shape[0] != self.triangles.shape[0]:
196+
if (len(self.mask.shape) != 1 or
197+
self.mask.shape[0] != self.triangles.shape[0]):
200198
raise ValueError('mask array must have same length as '
201199
'triangles array')
202200

lib/matplotlib/tri/tricontour.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _process_args(self, *args, **kwargs):
5050
x1 = tri.x.max()
5151
y0 = tri.y.min()
5252
y1 = tri.y.max()
53-
self.ax.update_datalim([(x0,y0), (x1,y1)])
53+
self.ax.update_datalim([(x0, y0), (x1, y1)])
5454
self.ax.autoscale_view()
5555

5656
self.cppContourGenerator = C
@@ -65,7 +65,7 @@ def _get_allsegs_and_allkinds(self):
6565
allkinds = []
6666
for lower, upper in zip(lowers, uppers):
6767
segs, kinds = self.cppContourGenerator.create_filled_contour(
68-
lower, upper)
68+
lower, upper)
6969
allsegs.append([segs])
7070
allkinds.append([kinds])
7171
else:
@@ -76,10 +76,12 @@ def _get_allsegs_and_allkinds(self):
7676
return allsegs, allkinds
7777

7878
def _contour_args(self, args, kwargs):
79-
if self.filled: fn = 'contourf'
80-
else: fn = 'contour'
81-
tri, args, kwargs = \
82-
Triangulation.get_from_args_and_kwargs(*args, **kwargs)
79+
if self.filled:
80+
fn = 'contourf'
81+
else:
82+
fn = 'contour'
83+
tri, args, kwargs = Triangulation.get_from_args_and_kwargs(*args,
84+
**kwargs)
8385
z = np.asarray(args[0])
8486
if z.shape != tri.x.shape:
8587
raise ValueError('z array must have same length as triangulation x'
@@ -275,14 +277,16 @@ def _contour_args(self, args, kwargs):
275277

276278

277279
def tricontour(ax, *args, **kwargs):
278-
if not ax._hold: ax.cla()
280+
if not ax._hold:
281+
ax.cla()
279282
kwargs['filled'] = False
280283
return TriContourSet(ax, *args, **kwargs)
281284
tricontour.__doc__ = TriContourSet.tricontour_doc
282285

283286

284287
def tricontourf(ax, *args, **kwargs):
285-
if not ax._hold: ax.cla()
288+
if not ax._hold:
289+
ax.cla()
286290
kwargs['filled'] = True
287291
return TriContourSet(ax, *args, **kwargs)
288292
tricontourf.__doc__ = TriContourSet.tricontour_doc

lib/matplotlib/tri/triinterpolate.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _interpolate_single_key(self, return_key, tri_index, x, y):
286286
elif return_key == 'dzdy':
287287
return self._plane_coefficients[tri_index, 1]
288288
else:
289-
raise ValueError("Invalid return_key: "+return_key)
289+
raise ValueError("Invalid return_key: " + return_key)
290290

291291

292292
class CubicTriInterpolator(TriInterpolator):
@@ -526,7 +526,7 @@ def _get_alpha_vec(x, y, tris_pts):
526526
ab = _transpose_vectorized(abT)
527527
x = np.expand_dims(x, ndim)
528528
y = np.expand_dims(y, ndim)
529-
OM = np.concatenate([x, y], ndim)-tris_pts[:, 0, :]
529+
OM = np.concatenate([x, y], ndim) - tris_pts[:, 0, :]
530530

531531
metric = _prod_vectorized(ab, abT)
532532
# Here we try to deal with the colinear cases.
@@ -563,8 +563,8 @@ def _get_jacobian(tris_pts):
563563
ksi: element parametric coordinates in triangle first apex
564564
local basis.
565565
"""
566-
a = np.array(tris_pts[:, 1, :]-tris_pts[:, 0, :])
567-
b = np.array(tris_pts[:, 2, :]-tris_pts[:, 0, :])
566+
a = np.array(tris_pts[:, 1, :] - tris_pts[:, 0, :])
567+
b = np.array(tris_pts[:, 2, :] - tris_pts[:, 0, :])
568568
J = _to_matrix_vectorized([[a[:, 0], a[:, 1]],
569569
[b[:, 0], b[:, 1]]])
570570
return J
@@ -595,9 +595,9 @@ def _compute_tri_eccentricities(tris_pts):
595595
dot_c = _prod_vectorized(_transpose_vectorized(c), c)[:, 0, 0]
596596
# Note that this line will raise a warning for dot_a, dot_b or dot_c
597597
# zeros, but we choose not to support triangles with duplicate points.
598-
return _to_matrix_vectorized([[(dot_c-dot_b)/dot_a],
599-
[(dot_a-dot_c)/dot_b],
600-
[(dot_b-dot_a)/dot_c]])
598+
return _to_matrix_vectorized([[(dot_c-dot_b) / dot_a],
599+
[(dot_a-dot_c) / dot_b],
600+
[(dot_b-dot_a) / dot_c]])
601601

602602

603603
# FEM element used for interpolation and for solving minimisation
@@ -1363,7 +1363,7 @@ def _cg(A, b, x0=None, tol=1.e-10, maxiter=1000):
13631363

13641364
# Following C. T. Kelley
13651365
while (np.sqrt(abs(rho)) > tol*b_norm) and (k < maxiter):
1366-
p = w+beta*p
1366+
p = w + beta*p
13671367
z = A.dot(p)
13681368
alpha = rho/np.dot(p, z)
13691369
r = r - alpha*z

lib/matplotlib/tri/tripcolor.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from matplotlib.tri.triangulation import Triangulation
55
import numpy as np
66

7+
78
def tripcolor(ax, *args, **kwargs):
89
"""
910
Create a pseudocolor plot of an unstructured triangular grid.
@@ -49,7 +50,8 @@ def tripcolor(ax, *args, **kwargs):
4950
5051
.. plot:: mpl_examples/pylab_examples/tripcolor_demo.py
5152
"""
52-
if not ax._hold: ax.cla()
53+
if not ax._hold:
54+
ax.cla()
5355

5456
alpha = kwargs.pop('alpha', 1.0)
5557
norm = kwargs.pop('norm', None)
@@ -61,7 +63,7 @@ def tripcolor(ax, *args, **kwargs):
6163

6264
tri, args, kwargs = Triangulation.get_from_args_and_kwargs(*args, **kwargs)
6365

64-
# C is the colors array, defined at either points or faces (i.e. triangles).
66+
# C is the colors array defined at either points or faces (i.e. triangles).
6567
# If facecolors is None, C are defined at points.
6668
# If facecolors is not None, C are defined at faces.
6769
if facecolors is not None:
@@ -74,17 +76,16 @@ def tripcolor(ax, *args, **kwargs):
7476
# length of C whether it refers to points or faces.
7577
# Do not do this for gouraud shading.
7678
if (facecolors is None and len(C) == len(tri.triangles) and
77-
len(C) != len(tri.x) and shading != 'gouraud'):
79+
len(C) != len(tri.x) and shading != 'gouraud'):
7880
facecolors = C
7981

8082
# Check length of C is OK.
81-
if ( (facecolors is None and len(C) != len(tri.x)) or
82-
(facecolors is not None and len(C) != len(tri.triangles)) ):
83+
if ((facecolors is None and len(C) != len(tri.x)) or
84+
(facecolors is not None and len(C) != len(tri.triangles))):
8385
raise ValueError('Length of color values array must be the same '
8486
'as either the number of triangulation points '
8587
'or triangles')
8688

87-
8889
# Handling of linewidths, shading, edgecolors and antialiased as
8990
# in Axes.pcolor
9091
linewidths = (0.25,)
@@ -105,7 +106,6 @@ def tripcolor(ax, *args, **kwargs):
105106
if 'antialiaseds' not in kwargs and ec.lower() == "none":
106107
kwargs['antialiaseds'] = False
107108

108-
109109
if shading == 'gouraud':
110110
if facecolors is not None:
111111
raise ValueError('Gouraud shading does not support the use '
@@ -118,8 +118,8 @@ def tripcolor(ax, *args, **kwargs):
118118
else:
119119
# Vertices of triangles.
120120
maskedTris = tri.get_masked_triangles()
121-
verts = np.concatenate((tri.x[maskedTris][...,np.newaxis],
122-
tri.y[maskedTris][...,np.newaxis]), axis=2)
121+
verts = np.concatenate((tri.x[maskedTris][..., np.newaxis],
122+
tri.y[maskedTris][..., np.newaxis]), axis=2)
123123

124124
# Color values.
125125
if facecolors is None:
@@ -133,7 +133,8 @@ def tripcolor(ax, *args, **kwargs):
133133

134134
collection.set_alpha(alpha)
135135
collection.set_array(C)
136-
if norm is not None: assert(isinstance(norm, Normalize))
136+
if norm is not None:
137+
assert(isinstance(norm, Normalize))
137138
collection.set_cmap(cmap)
138139
collection.set_norm(norm)
139140
if vmin is not None or vmax is not None:
@@ -147,7 +148,7 @@ def tripcolor(ax, *args, **kwargs):
147148
miny = tri.y.min()
148149
maxy = tri.y.max()
149150
corners = (minx, miny), (maxx, maxy)
150-
ax.update_datalim( corners)
151+
ax.update_datalim(corners)
151152
ax.autoscale_view()
152153
ax.add_collection(collection)
153154
return collection

0 commit comments

Comments
 (0)