Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb154e5

Browse filesBrowse files
committed
[examples] use np.radians/np.degrees where appropriate
1 parent 180c6d8 commit cb154e5
Copy full SHA for cb154e5

File tree

Expand file treeCollapse file tree

9 files changed

+18
-20
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+18
-20
lines changed

‎examples/animation/double_pendulum_animated.py

Copy file name to clipboardExpand all lines: examples/animation/double_pendulum_animated.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Double pendulum formula translated from the C code at
22
# http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c
33

4-
from numpy import sin, cos, pi, array
4+
from numpy import sin, cos
55
import numpy as np
66
import matplotlib.pyplot as plt
77
import scipy.integrate as integrate

‎examples/api/custom_projection_example.py

Copy file name to clipboardExpand all lines: examples/api/custom_projection_example.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ def format_coord(self, lon, lat):
271271
272272
In this case, we want them to be displayed in degrees N/S/E/W.
273273
"""
274-
lon = lon * (180.0 / np.pi)
275-
lat = lat * (180.0 / np.pi)
274+
lon = np.degrees(lon)
275+
lat = np.degrees(lat)
276276
if lat >= 0.0:
277277
ns = 'N'
278278
else:
@@ -294,8 +294,7 @@ def __init__(self, round_to=1.0):
294294
self._round_to = round_to
295295

296296
def __call__(self, x, pos=None):
297-
degrees = (x / np.pi) * 180.0
298-
degrees = round(degrees / self._round_to) * self._round_to
297+
degrees = round(np.degrees(x) / self._round_to) * self._round_to
299298
# \u00b0 : degree symbol
300299
return "%d\u00b0" % degrees
301300

@@ -347,7 +346,7 @@ def set_longitude_grid_ends(self, degrees):
347346
class -- it provides an interface to something that has no
348347
analogy in the base Axes class.
349348
"""
350-
longitude_cap = degrees * (np.pi / 180.0)
349+
longitude_cap = np.radians(degrees)
351350
# Change the xaxis gridlines transform so that it draws from
352351
# -degrees to degrees, rather than -pi to pi.
353352
self._xaxis_pretransform \

‎examples/api/custom_scale_example.py

Copy file name to clipboardExpand all lines: examples/api/custom_scale_example.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, axis, **kwargs):
4141
thresh: The degree above which to crop the data.
4242
"""
4343
mscale.ScaleBase.__init__(self)
44-
thresh = kwargs.pop("thresh", (85 / 180.0) * np.pi)
44+
thresh = kwargs.pop("thresh", np.radians(85))
4545
if thresh >= np.pi / 2.0:
4646
raise ValueError("thresh must be less than pi/2")
4747
self.thresh = thresh
@@ -72,11 +72,10 @@ def set_default_locators_and_formatters(self, axis):
7272
class DegreeFormatter(Formatter):
7373
def __call__(self, x, pos=None):
7474
# \u00b0 : degree symbol
75-
return "%d\u00b0" % ((x / np.pi) * 180.0)
75+
return "%d\u00b0" % (np.degrees(x))
7676

77-
deg2rad = np.pi / 180.0
7877
axis.set_major_locator(FixedLocator(
79-
np.arange(-90, 90, 10) * deg2rad))
78+
np.radians(np.arange(-90, 90, 10))))
8079
axis.set_major_formatter(DegreeFormatter())
8180
axis.set_minor_formatter(DegreeFormatter())
8281

@@ -159,7 +158,7 @@ def inverted(self):
159158
import matplotlib.pyplot as plt
160159

161160
t = np.arange(-180.0, 180.0, 0.1)
162-
s = t / 360.0 * np.pi
161+
s = np.radius(t)/2.
163162

164163
plt.plot(t, s, '-', lw=2)
165164
plt.gca().set_yscale('mercator')

‎examples/api/joinstyle.py

Copy file name to clipboardExpand all lines: examples/api/joinstyle.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def plot_angle(ax, x, y, angle, style):
11-
phi = angle/180*np.pi
11+
phi = np.radians(angle)
1212
xx = [x + .5, x, x + .5*np.cos(phi)]
1313
yy = [y, y, y + .5*np.sin(phi)]
1414
ax.plot(xx, yy, lw=8, color='blue', solid_joinstyle=style)

‎examples/api/radar_chart.py

Copy file name to clipboardExpand all lines: examples/api/radar_chart.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _close_line(self, line):
7676
line.set_data(x, y)
7777

7878
def set_varlabels(self, labels):
79-
self.set_thetagrids(theta*180/np.pi, labels)
79+
self.set_thetagrids(np.degrees(theta), labels)
8080

8181
def _gen_axes_patch(self):
8282
return self.draw_patch()

‎examples/api/sankey_demo_old.py

Copy file name to clipboardExpand all lines: examples/api/sankey_demo_old.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def sankey(ax,
4444

4545
def add_output(path, loss, sign=1):
4646
# Arrow tip height
47-
h = (loss/2 + w) * np.tan(outangle/180.*np.pi)
47+
h = (loss/2 + w) * np.tan(np.radians(outangle))
4848
move, (x, y) = path[-1] # Use last point as reference
4949
if sign == 0: # Final loss (horizontal)
5050
path.extend([(Path.LINETO, [x + dx, y]),
@@ -68,7 +68,7 @@ def add_output(path, loss, sign=1):
6868
outtips.append((sign, path[-5][1]))
6969

7070
def add_input(path, gain, sign=1):
71-
h = (gain / 2) * np.tan(inangle / 180. * np.pi) # Dip depth
71+
h = (gain / 2) * np.tan(np.radians(inangle)) # Dip depth
7272
move, (x, y) = path[-1] # Use last point as reference
7373
if sign == 0: # First gain (horizontal)
7474
path.extend([(Path.LINETO, [x - dx, y]),

‎examples/pylab_examples/tricontour_demo.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/tricontour_demo.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
6666
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
6767
[-0.077, 0.990], [-0.059, 0.993]])
68-
x = xy[:, 0]*180/3.14159
69-
y = xy[:, 1]*180/3.14159
68+
x = np.degrees(xy[:, 0])
69+
y = np.degrees(xy[:, 1])
7070
x0 = -5
7171
y0 = 52
7272
z = np.exp(-0.01*((x - x0)*(x - x0) + (y - y0)*(y - y0)))

‎examples/pylab_examples/triplot_demo.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/triplot_demo.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
6464
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
6565
[-0.077, 0.990], [-0.059, 0.993]])
66-
x = xy[:, 0]*180/3.14159
67-
y = xy[:, 1]*180/3.14159
66+
x = np.degrees(xy[:, 0])
67+
y = np.degrees(xy[:, 1])
6868

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

‎examples/units/ellipse_with_units.py

Copy file name to clipboardExpand all lines: examples/units/ellipse_with_units.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
x = 0.5 * width * np.cos(theta)
1717
y = 0.5 * height * np.sin(theta)
1818

19-
rtheta = angle*np.pi/180.
19+
rtheta = np.radians(angle)
2020
R = np.array([
2121
[np.cos(rtheta), -np.sin(rtheta)],
2222
[np.sin(rtheta), np.cos(rtheta)],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.