Permalink
Browse files

Improved PEP8 compliance.

  • Loading branch information...
1 parent 01ddc8a commit 88dc57ed2ed116622710e548d7db1da6d1d88f21 @ianthomas23 ianthomas23 committed Jan 8, 2013
Showing with 36 additions and 32 deletions.
  1. +2 −3 examples/pylab_examples/triinterp_demo.py
  2. +34 −29 lib/matplotlib/tests/test_triangulation.py
View
5 examples/pylab_examples/triinterp_demo.py
@@ -4,14 +4,13 @@
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
import numpy as np
-import math
# Create triangulation.
x = np.asarray([0, 1, 2, 3, 0.5, 1.5, 2.5, 1, 2, 1.5])
y = np.asarray([0, 0, 0, 0, 1, 1, 1, 2, 2, 3])
-triangles = [[0,1,4], [1,2,5], [2,3,6], [1,5,4], [2,6,5], [4,5,7], [5,6,8],
- [5,8,7], [7,8,9]]
+triangles = [[0, 1, 4], [1, 2, 5], [2, 3, 6], [1, 5, 4], [2, 6, 5], [4, 5, 7],
+ [5, 6, 8], [5, 8, 7], [7, 8, 9]]
triang = mtri.Triangulation(x, y, triangles)
# Interpolate to regularly-spaced quad grid.
View
63 lib/matplotlib/tests/test_triangulation.py
@@ -134,79 +134,83 @@ def test_no_modify():
def test_trifinder():
# Test points within triangles of masked triangulation.
- x,y = np.meshgrid(np.arange(4), np.arange(4))
+ x, y = np.meshgrid(np.arange(4), np.arange(4))
x = x.ravel()
y = y.ravel()
- triangles = [[0,1,4], [1,5,4], [1,2,5], [2,6,5], [2,3,6], [3,7,6], [4,5,8],
- [5,9,8], [5,6,9], [6,10,9], [6,7,10], [7,11,10], [8,9,12],
- [9,13,12], [9,10,13], [10,14,13], [10,11,14], [11,15,14]]
+ triangles = [[0, 1, 4], [1, 5, 4], [1, 2, 5], [2, 6, 5], [2, 3, 6],
+ [3, 7, 6], [4, 5, 8], [5, 9, 8], [5, 6, 9], [6, 10, 9],
+ [6, 7, 10], [7, 11, 10], [8, 9, 12], [9, 13, 12], [9, 10, 13],
+ [10, 14, 13], [10, 11, 14], [11, 15, 14]]
mask = np.zeros(len(triangles))
mask[8:10] = 1
triang = mtri.Triangulation(x, y, triangles, mask)
trifinder = triang.get_trifinder()
xs = [0.25, 1.25, 2.25, 3.25]
ys = [0.25, 1.25, 2.25, 3.25]
- xs,ys = np.meshgrid(xs,ys)
+ xs, ys = np.meshgrid(xs, ys)
xs = xs.ravel()
ys = ys.ravel()
tris = trifinder(xs, ys)
- assert_array_equal(tris, [0,2,4,-1,6,-1,10,-1,12,14,16,-1,-1,-1,-1,-1])
+ assert_array_equal(tris, [0, 2, 4, -1, 6, -1, 10, -1,
+ 12, 14, 16, -1, -1, -1, -1, -1])
tris = trifinder(xs-0.5, ys-0.5)
- assert_array_equal(tris, [-1,-1,-1,-1,-1,1,3,5,-1,7,-1,11,-1,13,15,17])
+ assert_array_equal(tris, [-1, -1, -1, -1, -1, 1, 3, 5,
+ -1, 7, -1, 11, -1, 13, 15, 17])
# Test points exactly on boundary edges of masked triangulation.
- xs = [0.5, 1.5, 2.5, 0.5, 1.5, 2.5, 1.5, 1.5, 0.0, 1.0, 2.0, 3.0]
- ys = [0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 1.0, 2.0, 1.5, 1.5, 1.5, 1.5]
+ xs = [0.5, 1.5, 2.5, 0.5, 1.5, 2.5, 1.5, 1.5, 0.0, 1.0, 2.0, 3.0]
+ ys = [0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 1.0, 2.0, 1.5, 1.5, 1.5, 1.5]
tris = trifinder(xs, ys)
- assert_array_equal(tris, [0,2,4,13,15,17,3,14,6,7,10,11])
+ assert_array_equal(tris, [0, 2, 4, 13, 15, 17, 3, 14, 6, 7, 10, 11])
# Test points exactly on boundary corners of masked triangulation.
xs = [0.0, 3.0]
ys = [0.0, 3.0]
tris = trifinder(xs, ys)
- assert_array_equal(tris, [0,17])
+ assert_array_equal(tris, [0, 17])
# Test triangles with horizontal colinear points. These are not valid
# triangulations, but we try to deal with the simplest violations.
delta = 0.0 # If +ve, triangulation is OK, if -ve triangulation invalid,
# if zero have colinear points but should pass tests anyway.
x = [1.5, 0, 1, 2, 3, 1.5, 1.5]
y = [-1, 0, 0, 0, 0, delta, 1]
- triangles = [[0,2,1], [0,3,2], [0,4,3], [1,2,5], [2,3,5], [3,4,5], [1,5,6],
- [4,6,5]]
+ triangles = [[0, 2, 1], [0, 3, 2], [0, 4, 3], [1, 2, 5], [2, 3, 5],
+ [3, 4, 5], [1, 5, 6], [4, 6, 5]]
triang = mtri.Triangulation(x, y, triangles)
trifinder = triang.get_trifinder()
xs = [-0.1, 0.4, 0.9, 1.4, 1.9, 2.4, 2.9]
- ys = [-0.1,0.1]
- xs,ys = np.meshgrid(xs, ys)
+ ys = [-0.1, 0.1]
+ xs, ys = np.meshgrid(xs, ys)
tris = trifinder(xs, ys)
- assert_array_equal(tris, [[-1,0,0,1,1,2,-1],[-1,6,6,6,7,7,-1]])
+ assert_array_equal(tris, [[-1, 0, 0, 1, 1, 2, -1],
+ [-1, 6, 6, 6, 7, 7, -1]])
# Test triangles with vertical colinear points. These are not valid
# triangulations, but we try to deal with the simplest violations.
delta = 0.0 # If +ve, triangulation is OK, if -ve triangulation invalid,
# if zero have colinear points but should pass tests anyway.
x = [-1, -delta, 0, 0, 0, 0, 1]
y = [1.5, 1.5, 0, 1, 2, 3, 1.5]
- triangles = [[0,1,2], [0,1,5], [1,2,3], [1,3,4], [1,4,5], [2,6,3], [3,6,4],
- [4,6,5]]
+ triangles = [[0, 1, 2], [0, 1, 5], [1, 2, 3], [1, 3, 4], [1, 4, 5],
+ [2, 6, 3], [3, 6, 4], [4, 6, 5]]
triang = mtri.Triangulation(x, y, triangles)
trifinder = triang.get_trifinder()
- xs = [-0.1,0.1]
+ xs = [-0.1, 0.1]
ys = [-0.1, 0.4, 0.9, 1.4, 1.9, 2.4, 2.9]
- xs,ys = np.meshgrid(xs, ys)
+ xs, ys = np.meshgrid(xs, ys)
tris = trifinder(xs, ys)
- assert_array_equal(tris, [[-1,-1], [0,5], [0,5], [0,6], [1,6], [1,7],
- [-1,-1]])
+ assert_array_equal(tris, [[-1, -1], [0, 5], [0, 5], [0, 6], [1, 6], [1, 7],
+ [-1, -1]])
# Test that changing triangulation by setting a mask causes the trifinder
# to be reinitialised.
x = [0, 1, 0, 1]
y = [0, 0, 1, 1]
- triangles = [[0,1,2], [1,3,2]]
+ triangles = [[0, 1, 2], [1, 3, 2]]
triang = mtri.Triangulation(x, y, triangles)
trifinder = triang.get_trifinder()
@@ -222,21 +226,22 @@ def test_trifinder():
def test_triinterp():
# Test points within triangles of masked triangulation.
- x,y = np.meshgrid(np.arange(4), np.arange(4))
+ x, y = np.meshgrid(np.arange(4), np.arange(4))
x = x.ravel()
y = y.ravel()
z = 1.23*x - 4.79*y
- triangles = [[0,1,4], [1,5,4], [1,2,5], [2,6,5], [2,3,6], [3,7,6], [4,5,8],
- [5,9,8], [5,6,9], [6,10,9], [6,7,10], [7,11,10], [8,9,12],
- [9,13,12], [9,10,13], [10,14,13], [10,11,14], [11,15,14]]
+ triangles = [[0, 1, 4], [1, 5, 4], [1, 2, 5], [2, 6, 5], [2, 3, 6],
+ [3, 7, 6], [4, 5, 8], [5, 9, 8], [5, 6, 9], [6, 10, 9],
+ [6, 7, 10], [7, 11, 10], [8, 9, 12], [9, 13, 12], [9, 10, 13],
+ [10, 14, 13], [10, 11, 14], [11, 15, 14]]
mask = np.zeros(len(triangles))
mask[8:10] = 1
triang = mtri.Triangulation(x, y, triangles, mask)
linear_interp = mtri.LinearTriInterpolator(triang, z)
xs = np.linspace(0.25, 2.75, 6)
ys = [0.25, 0.75, 2.25, 2.75]
- xs,ys = np.meshgrid(xs,ys)
+ xs, ys = np.meshgrid(xs, ys)
xs = xs.ravel()
ys = ys.ravel()
zs = linear_interp(xs, ys)
@@ -245,7 +250,7 @@ def test_triinterp():
# Test points outside triangulation.
xs = [-0.25, 1.25, 1.75, 3.25]
ys = xs
- xs, ys = np.meshgrid(xs,ys)
+ xs, ys = np.meshgrid(xs, ys)
xs = xs.ravel()
ys = ys.ravel()
zs = linear_interp(xs, ys)

0 comments on commit 88dc57e

Please sign in to comment.