Skip to content

Commit 09bfad2

Browse files
committed
hypot / **2 instead of x * x
1 parent 7996676 commit 09bfad2

30 files changed

+128
-141
lines changed

examples/animation/unchained.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Generate random data
2626
data = np.random.uniform(0, 1, (64, 75))
2727
X = np.linspace(-1, 1, data.shape[-1])
28-
G = 1.5 * np.exp(-4 * X * X)
28+
G = 1.5 * np.exp(-4 * X ** 2)
2929

3030
# Generate line plots
3131
lines = []

examples/api/custom_projection_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ def transform_non_affine(self, xy):
440440

441441
quarter_x = 0.25 * x
442442
half_y = 0.5 * y
443-
z = np.sqrt(1.0 - quarter_x*quarter_x - half_y*half_y)
444-
longitude = 2 * np.arctan((z*x) / (2.0 * (2.0*z*z - 1.0)))
443+
z = np.sqrt(1 - quarter_x * quarter_x - half_y * half_y)
444+
longitude = 2 * np.arctan((z * x) / (2 * (2 * z ** 2 - 1)))
445445
latitude = np.arcsin(y*z)
446446
return np.concatenate((longitude, latitude), 1)
447447
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__

examples/api/scatter_piecharts.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Thanks to Manuel Metz for the example
99
"""
10-
import math
10+
1111
import numpy as np
1212
import matplotlib.pyplot as plt
1313

@@ -16,35 +16,33 @@
1616
r2 = r1 + 0.4 # 40%
1717

1818
# define some sizes of the scatter marker
19-
sizes = [60, 80, 120]
19+
sizes = np.array([60, 80, 120])
2020

2121
# calculate the points of the first pie marker
2222
#
2323
# these are just the origin (0,0) +
2424
# some points on a circle cos,sin
25-
x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist()
26-
y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist()
27-
25+
x = [0] + np.cos(np.linspace(0, 2 * np.pi * r1, 10)).tolist()
26+
y = [0] + np.sin(np.linspace(0, 2 * np.pi * r1, 10)).tolist()
2827
xy1 = list(zip(x, y))
29-
s1 = max(max(x), max(y))
28+
s1 = np.max(xy1)
3029

31-
# ...
32-
x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
33-
y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
30+
x = [0] + np.cos(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist()
31+
y = [0] + np.sin(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist()
3432
xy2 = list(zip(x, y))
35-
s2 = max(max(x), max(y))
33+
s2 = np.max(xy2)
3634

37-
x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
38-
y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
35+
x = [0] + np.cos(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist()
36+
y = [0] + np.sin(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist()
3937
xy3 = list(zip(x, y))
40-
s3 = max(max(x), max(y))
38+
s3 = np.max(xy3)
4139

4240
fig, ax = plt.subplots()
43-
ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0),
44-
s=[s1*s1*_ for _ in sizes], facecolor='blue')
45-
ax.scatter(np.arange(3), np.arange(3), marker=(xy2, 0),
46-
s=[s2*s2*_ for _ in sizes], facecolor='green')
47-
ax.scatter(np.arange(3), np.arange(3), marker=(xy3, 0),
48-
s=[s3*s3*_ for _ in sizes], facecolor='red')
41+
ax.scatter(range(3), range(3), marker=(xy1, 0),
42+
s=s1 ** 2 * sizes, facecolor='blue')
43+
ax.scatter(range(3), range(3), marker=(xy2, 0),
44+
s=s2 ** 2 * sizes, facecolor='green')
45+
ax.scatter(range(3), range(3), marker=(xy3, 0),
46+
s=s3 ** 2 * sizes, facecolor='red')
4947

5048
plt.show()

examples/event_handling/timers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def update_title(axes):
1212
fig, ax = plt.subplots()
1313

1414
x = np.linspace(-3, 3)
15-
ax.plot(x, x*x)
15+
ax.plot(x, x ** 2)
1616

1717
# Create a new timer object. Set the interval to 100 milliseconds
1818
# (1000 is default) and tell the timer what function should be called.

examples/event_handling/trifinder_event_demo.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ def motion_notify(event):
3535
n_radii = 5
3636
min_radius = 0.25
3737
radii = np.linspace(min_radius, 0.95, n_radii)
38-
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
38+
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
3939
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
4040
angles[:, 1::2] += math.pi / n_angles
41-
x = (radii*np.cos(angles)).flatten()
42-
y = (radii*np.sin(angles)).flatten()
41+
x = (radii * np.cos(angles)).flatten()
42+
y = (radii * np.sin(angles)).flatten()
4343
triangulation = Triangulation(x, y)
44-
xmid = x[triangulation.triangles].mean(axis=1)
45-
ymid = y[triangulation.triangles].mean(axis=1)
46-
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
47-
triangulation.set_mask(mask)
44+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
45+
y[triang.triangles].mean(axis=1))
46+
< min_radius)
4847

4948
# Use the triangulation's default TriFinder object.
5049
trifinder = triangulation.get_trifinder()

examples/mplot3d/tricontour3d_demo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@
2020

2121
# Create the mesh in polar coordinates and compute x, y, z.
2222
radii = np.linspace(min_radius, 0.95, n_radii)
23-
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
23+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
2424
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
25-
angles[:, 1::2] += np.pi/n_angles
25+
angles[:, 1::2] += np.pi / n_angles
2626

27-
x = (radii*np.cos(angles)).flatten()
28-
y = (radii*np.sin(angles)).flatten()
29-
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
27+
x = (radii * np.cos(angles)).flatten()
28+
y = (radii * np.sin(angles)).flatten()
29+
z = (np.cos(radii) * np.cos(3 * angles)).flatten()
3030

3131
# Create a custom triangulation.
3232
triang = tri.Triangulation(x, y)
3333

3434
# Mask off unwanted triangles.
35-
xmid = x[triang.triangles].mean(axis=1)
36-
ymid = y[triang.triangles].mean(axis=1)
37-
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
38-
triang.set_mask(mask)
35+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
36+
y[triang.triangles].mean(axis=1))
37+
< min_radius)
3938

4039
fig = plt.figure()
4140
ax = fig.gca(projection='3d')

examples/mplot3d/tricontourf3d_demo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,21 @@
2121

2222
# Create the mesh in polar coordinates and compute x, y, z.
2323
radii = np.linspace(min_radius, 0.95, n_radii)
24-
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
24+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
2525
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
26-
angles[:, 1::2] += np.pi/n_angles
26+
angles[:, 1::2] += np.pi / n_angles
2727

28-
x = (radii*np.cos(angles)).flatten()
29-
y = (radii*np.sin(angles)).flatten()
30-
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
28+
x = (radii * np.cos(angles)).flatten()
29+
y = (radii * np.sin(angles)).flatten()
30+
z = (np.cos(radii) * np.cos(3 * angles)).flatten()
3131

3232
# Create a custom triangulation.
3333
triang = tri.Triangulation(x, y)
3434

3535
# Mask off unwanted triangles.
36-
xmid = x[triang.triangles].mean(axis=1)
37-
ymid = y[triang.triangles].mean(axis=1)
38-
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
39-
triang.set_mask(mask)
36+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
37+
y[triang.triangles].mean(axis=1))
38+
< min_radius)
4039

4140
fig = plt.figure()
4241
ax = fig.gca(projection='3d')

examples/mplot3d/trisurf3d_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
1818
radii = np.linspace(0.125, 1.0, n_radii)
19-
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
19+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
2020

2121
# Repeat all angles for each radius.
2222
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
2323

2424
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
2525
# (0, 0) is manually added at this stage, so there will be no duplicate
2626
# points in the (x, y) plane.
27-
x = np.append(0, (radii*np.cos(angles)).flatten())
28-
y = np.append(0, (radii*np.sin(angles)).flatten())
27+
x = np.append(0, (radii * np.cos(angles)).flatten())
28+
y = np.append(0, (radii * np.sin(angles)).flatten())
2929

3030
# Compute z to make the pringle surface.
31-
z = np.sin(-x*y)
31+
z = np.sin(-x * y)
3232

3333
fig = plt.figure()
3434
ax = fig.gca(projection='3d')

examples/mplot3d/trisurf3d_demo2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@
5454
min_radius = 0.25
5555
radii = np.linspace(min_radius, 0.95, n_radii)
5656

57-
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
57+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
5858
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
5959
angles[:, 1::2] += np.pi/n_angles
6060

6161
# Map radius, angle pairs to x, y, z points.
62-
x = (radii*np.cos(angles)).flatten()
63-
y = (radii*np.sin(angles)).flatten()
64-
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
62+
x = (radii * np.cos(angles)).flatten()
63+
y = (radii * np.sin(angles)).flatten()
64+
z = (np.cos(radii) * np.cos(3 * angles)).flatten()
6565

6666
# Create the Triangulation; no triangles so Delaunay triangulation created.
6767
triang = mtri.Triangulation(x, y)

examples/pylab_examples/annotation_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
fig = plt.figure()
9292
ax = fig.add_subplot(111, projection='polar')
9393
r = np.arange(0, 1, 0.001)
94-
theta = 2*2*np.pi*r
94+
theta = 4 * np.pi * r
9595
line, = ax.plot(theta, r)
9696

9797
ind = 800

0 commit comments

Comments
 (0)