Skip to content

Commit f15e8f4

Browse files
committed
Some more angular conversions.
1 parent f24cbca commit f15e8f4

File tree

10 files changed

+43
-59
lines changed

10 files changed

+43
-59
lines changed

examples/event_handling/trifinder_event_demo.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from matplotlib.tri import Triangulation
88
from matplotlib.patches import Polygon
99
import numpy as np
10-
import math
1110

1211

1312
def update_polygon(tri):
@@ -35,9 +34,9 @@ def motion_notify(event):
3534
n_radii = 5
3635
min_radius = 0.25
3736
radii = np.linspace(min_radius, 0.95, n_radii)
38-
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
37+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
3938
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
40-
angles[:, 1::2] += math.pi / n_angles
39+
angles[:, 1::2] += np.pi / n_angles
4140
x = (radii * np.cos(angles)).flatten()
4241
y = (radii * np.sin(angles)).flatten()
4342
triangulation = Triangulation(x, y)

examples/pylab_examples/tricontour_demo.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import matplotlib.pyplot as plt
55
import matplotlib.tri as tri
66
import numpy as np
7-
import math
87

98
# Creating a Triangulation without specifying the triangles results in the
109
# Delaunay triangulation of the points.
@@ -15,9 +14,9 @@
1514
min_radius = 0.25
1615
radii = np.linspace(min_radius, 0.95, n_radii)
1716

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

2221
x = (radii * np.cos(angles)).flatten()
2322
y = (radii * np.sin(angles)).flatten()

examples/pylab_examples/tricontour_smooth_user.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import matplotlib.pyplot as plt
77
import matplotlib.cm as cm
88
import numpy as np
9-
import math
109

1110

1211
#-----------------------------------------------------------------------------
@@ -32,9 +31,9 @@ def function_z(x, y):
3231
min_radius = 0.15
3332
radii = np.linspace(min_radius, 0.95, n_radii)
3433

35-
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
34+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
3635
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
37-
angles[:, 1::2] += math.pi / n_angles
36+
angles[:, 1::2] += np.pi / n_angles
3837

3938
x = (radii * np.cos(angles)).flatten()
4039
y = (radii * np.sin(angles)).flatten()

examples/pylab_examples/trigradient_demo.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""
22
Demonstrates computation of gradient with matplotlib.tri.CubicTriInterpolator.
33
"""
4-
from matplotlib.tri import Triangulation, UniformTriRefiner,\
5-
CubicTriInterpolator
4+
from matplotlib.tri import (
5+
Triangulation, UniformTriRefiner, CubicTriInterpolator)
66
import matplotlib.pyplot as plt
77
import matplotlib.cm as cm
88
import numpy as np
9-
import math
109

1110

1211
#-----------------------------------------------------------------------------
@@ -29,9 +28,9 @@ def dipole_potential(x, y):
2928
min_radius = 0.2
3029
radii = np.linspace(min_radius, 0.95, n_radii)
3130

32-
angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False)
31+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
3332
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
34-
angles[:, 1::2] += math.pi / n_angles
33+
angles[:, 1::2] += np.pi / n_angles
3534

3635
x = (radii * np.cos(angles)).flatten()
3736
y = (radii * np.sin(angles)).flatten()

examples/pylab_examples/tripcolor_demo.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import matplotlib.pyplot as plt
55
import matplotlib.tri as tri
66
import numpy as np
7-
import math
87

98
# Creating a Triangulation without specifying the triangles results in the
109
# Delaunay triangulation of the points.
@@ -15,13 +14,13 @@
1514
min_radius = 0.25
1615
radii = np.linspace(min_radius, 0.95, n_radii)
1716

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

22-
x = (radii*np.cos(angles)).flatten()
23-
y = (radii*np.sin(angles)).flatten()
24-
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
21+
x = (radii * np.cos(angles)).flatten()
22+
y = (radii * np.sin(angles)).flatten()
23+
z = (np.cos(radii) * np.cos(3 * angles)).flatten()
2524

2625
# Create the Triangulation; no triangles so Delaunay triangulation created.
2726
triang = tri.Triangulation(x, y)

examples/pylab_examples/triplot_demo.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import matplotlib.pyplot as plt
55
import matplotlib.tri as tri
66
import numpy as np
7-
import math
87

98
# Creating a Triangulation without specifying the triangles results in the
109
# Delaunay triangulation of the points.
@@ -15,9 +14,9 @@
1514
min_radius = 0.25
1615
radii = np.linspace(min_radius, 0.95, n_radii)
1716

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

2221
x = (radii * np.cos(angles)).flatten()
2322
y = (radii * np.sin(angles)).flatten()

lib/matplotlib/axes/_axes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2604,7 +2604,7 @@ def get_next_color():
26042604
for frac, label, expl in cbook.safezip(x, labels, explode):
26052605
x, y = center
26062606
theta2 = (theta1 + frac) if counterclock else (theta1 - frac)
2607-
thetam = 2 * math.pi * 0.5 * (theta1 + theta2)
2607+
thetam = 2 * np.pi * 0.5 * (theta1 + theta2)
26082608
x += expl * math.cos(thetam)
26092609
y += expl * math.sin(thetam)
26102610

@@ -6613,7 +6613,6 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
66136613
if logi == 0:
66146614
logi = .1
66156615
step = 10 * logi
6616-
#print vmin, vmax, step, intv, math.floor(vmin), math.ceil(vmax)+1
66176616
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
66186617
self.set_yticks(ticks)
66196618

lib/matplotlib/backends/backend_wx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
318318
if angle == 0.0:
319319
gfx_ctx.DrawText(s, x, y)
320320
else:
321-
rads = angle / 180.0 * math.pi
321+
rads = math.radians(angle)
322322
xo = h * math.sin(rads)
323323
yo = h * math.cos(rads)
324324
gfx_ctx.DrawRotatedText(s, x - xo, y - yo, rads)

lib/matplotlib/patches.py

+19-28
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ def getpoints(self, x1, y1, x2, y2, k):
13401340
line and intersects (*x2*, *y2*) and the distance from (*x2*,
13411341
*y2*) of the returned points is *k*.
13421342
"""
1343-
x1, y1, x2, y2, k = list(map(float, (x1, y1, x2, y2, k)))
1343+
x1, y1, x2, y2, k = map(float, (x1, y1, x2, y2, k))
13441344

13451345
if y2 - y1 == 0:
13461346
return x2, y2 + k, x2, y2 - k
@@ -1353,10 +1353,10 @@ def getpoints(self, x1, y1, x2, y2, k):
13531353
b = -2 * y2
13541354
c = y2 ** 2. - k ** 2. * pm ** 2. / (1. + pm ** 2.)
13551355

1356-
y3a = (-b + math.sqrt(b ** 2. - 4 * a * c)) / (2. * a)
1356+
y3a = (-b + math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
13571357
x3a = (y3a - y2) / pm + x2
13581358

1359-
y3b = (-b - math.sqrt(b ** 2. - 4 * a * c)) / (2. * a)
1359+
y3b = (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
13601360
x3b = (y3b - y2) / pm + x2
13611361
return x3a, y3a, x3b, y3b
13621362

@@ -2849,10 +2849,10 @@ def connect(self, posA, posB):
28492849
x1, y1 = posA
28502850
x2, y2 = posB
28512851

2852-
cosA, sinA = (math.cos(self.angleA / 180. * math.pi),
2853-
math.sin(self.angleA / 180. * math.pi))
2854-
cosB, sinB = (math.cos(self.angleB / 180. * math.pi),
2855-
math.sin(self.angleB / 180. * math.pi))
2852+
cosA = math.cos(math.radians(self.angleA))
2853+
sinA = math.sin(math.radians(self.angleA))
2854+
cosB = math.cos(math.radians(self.angleB))
2855+
sinB = math.sin(math.radians(self.angleB))
28562856

28572857
cx, cy = get_intersection(x1, y1, cosA, sinA,
28582858
x2, y2, cosB, sinB)
@@ -2894,10 +2894,10 @@ def connect(self, posA, posB):
28942894
x1, y1 = posA
28952895
x2, y2 = posB
28962896

2897-
cosA, sinA = (math.cos(self.angleA / 180. * math.pi),
2898-
math.sin(self.angleA / 180. * math.pi))
2899-
cosB, sinB = (math.cos(self.angleB / 180. * math.pi),
2900-
math.sin(self.angleB / 180. * math.pi))
2897+
cosA = math.cos(math.radians(self.angleA))
2898+
sinA = math.sin(math.radians(self.angleA))
2899+
cosB = math.cos(math.radians(self.angleB))
2900+
sinB = math.sin(math.radians(self.angleB))
29012901

29022902
cx, cy = get_intersection(x1, y1, cosA, sinA,
29032903
x2, y2, cosB, sinB)
@@ -2970,17 +2970,17 @@ def connect(self, posA, posB):
29702970
codes = [Path.MOVETO]
29712971

29722972
if self.armA:
2973-
cosA = math.cos(self.angleA / 180. * math.pi)
2974-
sinA = math.sin(self.angleA / 180. * math.pi)
2973+
cosA = math.cos(math.radians(self.angleA))
2974+
sinA = math.sin(math.radians(self.angleA))
29752975
# x_armA, y_armB
29762976
d = self.armA - self.rad
29772977
rounded.append((x1 + d * cosA, y1 + d * sinA))
29782978
d = self.armA
29792979
rounded.append((x1 + d * cosA, y1 + d * sinA))
29802980

29812981
if self.armB:
2982-
cosB = math.cos(self.angleB / 180. * math.pi)
2983-
sinB = math.sin(self.angleB / 180. * math.pi)
2982+
cosB = math.cos(math.radians(self.angleB))
2983+
sinB = math.sin(math.radians(self.angleB))
29842984
x_armB, y_armB = x2 + self.armB * cosB, y2 + self.armB * sinB
29852985

29862986
if rounded:
@@ -3067,18 +3067,10 @@ def connect(self, posA, posB):
30673067
armA, armB = self.armA, self.armB
30683068

30693069
if self.angle is not None:
3070-
#angle = self.angle % 180.
3071-
#if angle < 0. or angle > 180.:
3072-
# angle
3073-
#theta0 = (self.angle%180.)/180.*math.pi
3074-
theta0 = self.angle / 180. * math.pi
3075-
#theta0 = (((self.angle+90)%180.) - 90.)/180.*math.pi
3070+
theta0 = np.deg2rad(self.angle)
30763071
dtheta = theta1 - theta0
30773072
dl = dd * math.sin(dtheta)
3078-
30793073
dL = dd * math.cos(dtheta)
3080-
3081-
#x2, y2 = x2 + dl*ddy, y2 - dl*ddx
30823074
x2, y2 = x1 + dL * math.cos(theta0), y1 + dL * math.sin(theta0)
30833075

30843076
armB = armB - dl
@@ -3336,8 +3328,8 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
33363328

33373329
def transmute(self, path, mutation_size, linewidth):
33383330

3339-
head_length, head_width = self.head_length * mutation_size, \
3340-
self.head_width * mutation_size
3331+
head_length = self.head_length * mutation_size
3332+
head_width = self.head_width * mutation_size
33413333
head_dist = math.sqrt(head_length ** 2 + head_width ** 2)
33423334
cos_t, sin_t = head_length / head_dist, head_width / head_dist
33433335

@@ -3346,8 +3338,7 @@ def transmute(self, path, mutation_size, linewidth):
33463338
x1, y1 = path.vertices[1]
33473339

33483340
# If there is no room for an arrow and a line, then skip the arrow
3349-
has_begin_arrow = (self.beginarrow and
3350-
not ((x0 == x1) and (y0 == y1)))
3341+
has_begin_arrow = self.beginarrow and not (x0 == x1 and y0 == y1)
33513342
if has_begin_arrow:
33523343
verticesA, codesA, ddxA, ddyA = \
33533344
self._get_arrow_wedge(x1, y1, x0, y0,

lib/matplotlib/projections/polar.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import six
55

6-
import math
76
import warnings
87

98
import numpy as np
@@ -17,9 +16,10 @@
1716
from matplotlib.patches import Circle
1817
from matplotlib.path import Path
1918
from matplotlib.ticker import Formatter, Locator, FormatStrFormatter
20-
from matplotlib.transforms import Affine2D, Affine2DBase, Bbox, \
21-
BboxTransformTo, IdentityTransform, Transform, TransformWrapper, \
22-
ScaledTranslation, blended_transform_factory, BboxTransformToMaxOnly
19+
from matplotlib.transforms import (
20+
Affine2D, Affine2DBase, Bbox, BboxTransformTo, IdentityTransform,
21+
Transform, TransformWrapper, ScaledTranslation, blended_transform_factory,
22+
BboxTransformToMaxOnly)
2323
import matplotlib.spines as mspines
2424

2525

@@ -591,7 +591,7 @@ def format_coord(self, theta, r):
591591
Return a format string formatting the coordinate using Unicode
592592
characters.
593593
"""
594-
theta /= math.pi
594+
theta /= np.pi
595595
# \u03b8: lower-case theta
596596
# \u03c0: lower-case pi
597597
# \u00b0: degree symbol

0 commit comments

Comments
 (0)