Skip to content

Commit 69702f3

Browse files
committed
np.pi / np.deg2rad / np.rad2deg where appropriate.
1 parent cdb830d commit 69702f3

File tree

19 files changed

+4755
-4761
lines changed

19 files changed

+4755
-4761
lines changed

examples/api/custom_projection_example.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def __init__(self, round_to=1.0):
4343
self._round_to = round_to
4444

4545
def __call__(self, x, pos=None):
46-
degrees = (x / np.pi) * 180.0
47-
degrees = np.round(degrees / self._round_to) * self._round_to
46+
degrees = np.round(np.rad2deg(x) / self._round_to) * self._round_to
4847
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
4948
return r"$%0.0f^\circ$" % degrees
5049
else:
@@ -278,8 +277,7 @@ def format_coord(self, lon, lat):
278277
279278
In this case, we want them to be displayed in degrees N/S/E/W.
280279
"""
281-
lon = lon * (180.0 / np.pi)
282-
lat = lat * (180.0 / np.pi)
280+
lon, lat = np.rad2deg([lon, lat])
283281
if lat >= 0.0:
284282
ns = 'N'
285283
else:
@@ -330,7 +328,7 @@ def set_longitude_grid_ends(self, degrees):
330328
class -- it provides an interface to something that has no
331329
analogy in the base Axes class.
332330
"""
333-
self._longitude_cap = degrees * (np.pi / 180.0)
331+
self._longitude_cap = np.deg2rad(degrees)
334332
self._xaxis_pretransform \
335333
.clear() \
336334
.scale(1.0, self._longitude_cap * 2.0) \

examples/mplot3d/pathpatch3d_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def text3d(ax, xyz, s, zdir="z", size=None, angle=0, usetex=False, **kwargs):
4949
text3d(ax, (4, -2, 0), "X-axis", zdir="z", size=.5, usetex=False,
5050
ec="none", fc="k")
5151
text3d(ax, (12, 4, 0), "Y-axis", zdir="z", size=.5, usetex=False,
52-
angle=.5*3.14159, ec="none", fc="k")
52+
angle=np.pi / 2, ec="none", fc="k")
5353
text3d(ax, (12, 10, 4), "Z-axis", zdir="y", size=.5, usetex=False,
54-
angle=.5*3.14159, ec="none", fc="k")
54+
angle=np.pi / 2, ec="none", fc="k")
5555

5656
# Write a Latex formula on the z=0 'floor'
5757
text3d(ax, (1, 5, 0),

examples/pylab_examples/leftventricle_bulleye.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
5959

6060
# Create the bounds for the segments 1-12
6161
for i in range(6):
62-
theta_i = i*60*np.pi/180
62+
theta_i = np.deg2rad(i * 60)
6363
ax.plot([theta_i, theta_i], [r[1], 1], '-k', lw=linewidth)
6464

6565
# Create the bounds for the segmentss 13-16
6666
for i in range(4):
67-
theta_i = i*90*np.pi/180 - 45*np.pi/180
67+
theta_i = np.deg2rad(i * 90 - 45)
6868
ax.plot([theta_i, theta_i], [r[0], r[1]], '-k', lw=linewidth)
6969

7070
# Fill the segments 1-6
7171
r0 = r[2:4]
7272
r0 = np.repeat(r0[:, np.newaxis], 128, axis=1).T
7373
for i in range(6):
7474
# First segment start at 60 degrees
75-
theta0 = theta[i*128:i*128+128] + 60*np.pi/180
75+
theta0 = theta[i*128:i*128+128] + np.deg2rad(60)
7676
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
7777
z = np.ones((128, 2))*data[i]
7878
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
@@ -86,7 +86,7 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
8686
r0 = np.repeat(r0[:, np.newaxis], 128, axis=1).T
8787
for i in range(6):
8888
# First segment start at 60 degrees
89-
theta0 = theta[i*128:i*128+128] + 60*np.pi/180
89+
theta0 = theta[i*128:i*128+128] + np.deg2rad(60)
9090
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
9191
z = np.ones((128, 2))*data[i+6]
9292
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
@@ -100,7 +100,7 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
100100
r0 = np.repeat(r0[:, np.newaxis], 192, axis=1).T
101101
for i in range(4):
102102
# First segment start at 45 degrees
103-
theta0 = theta[i*192:i*192+192] + 45*np.pi/180
103+
theta0 = theta[i*192:i*192+192] + np.deg2rad(45)
104104
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
105105
z = np.ones((192, 2))*data[i+12]
106106
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)

examples/pylab_examples/tripcolor_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@
7272
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
7373
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
7474
[-0.077, 0.990], [-0.059, 0.993]])
75-
x = xy[:, 0]*180/3.14159
76-
y = xy[:, 1]*180/3.14159
75+
x, y = np.rad2deg(xy).T
7776

7877
triangles = np.asarray([
7978
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],

examples/units/ellipse_with_units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
width, height = 1e-1*cm, 3e-1*cm
1313
angle = -30
1414

15-
theta = np.arange(0.0, 360.0, 1.0)*np.pi/180.0
15+
theta = np.deg2rad(np.arange(0.0, 360.0, 1.0))
1616
x = 0.5 * width * np.cos(theta)
1717
y = 0.5 * height * np.sin(theta)
1818

examples/user_interfaces/embedding_in_tk_canvas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def draw_figure(canvas, figure, loc=(0, 0)):
4242
canvas.pack()
4343

4444
# Generate some example data
45-
X = np.linspace(0, 2.0*3.14, 50)
45+
X = np.linspace(0, 2 * np.pi, 50)
4646
Y = np.sin(X)
4747

4848
# Create the figure we desire to add to an existing canvas

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
647647
usetex=False)
648648

649649
path = Path(verts, codes)
650-
angle = angle / 180. * 3.141592
650+
angle = np.deg2rad(angle)
651651
if self.flipy():
652652
transform = Affine2D().scale(fontsize / text2path.FONT_SCALE,
653653
fontsize / text2path.FONT_SCALE)

lib/matplotlib/backends/backend_cairo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
283283

284284
ctx.save()
285285
if angle:
286-
ctx.rotate (-angle * np.pi / 180)
286+
ctx.rotate(np.deg2rad(-angle))
287287
ctx.set_font_size (size)
288288

289289
if HAS_CAIRO_CFFI:
@@ -306,7 +306,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
306306
ctx.save()
307307
ctx.translate(x, y)
308308
if angle:
309-
ctx.rotate (-angle * np.pi / 180)
309+
ctx.rotate(np.deg2rad(-angle))
310310

311311
for font, fontsize, s, ox, oy in glyphs:
312312
ctx.new_path()

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
10411041
# Don't do vertical anchor alignment. Most applications do not
10421042
# support 'alignment-baseline' yet. Apply the vertical layout
10431043
# to the anchor point manually for now.
1044-
angle_rad = angle * np.pi / 180.
1044+
angle_rad = np.deg2rad(angle)
10451045
dir_vert = np.array([np.sin(angle_rad), np.cos(angle_rad)])
10461046
v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
10471047
ax = ax + v_offset * dir_vert[0]

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
15671567
Collection.__init__(self, **kwargs)
15681568
self._widths = 0.5 * np.asarray(widths).ravel()
15691569
self._heights = 0.5 * np.asarray(heights).ravel()
1570-
self._angles = np.asarray(angles).ravel() * (np.pi / 180.0)
1570+
self._angles = np.deg2rad(angles).ravel()
15711571
self._units = units
15721572
self.set_transform(transforms.IdentityTransform())
15731573
self._transforms = np.empty((0, 3, 3))

0 commit comments

Comments
 (0)