Skip to content

[examples] use np.radians/np.degrees where appropriate #3814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/animation/double_pendulum_animated.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Double pendulum formula translated from the C code at
# http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c

from numpy import sin, cos, pi, array
from numpy import sin, cos
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
Expand Down
9 changes: 4 additions & 5 deletions examples/api/custom_projection_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ def format_coord(self, lon, lat):

In this case, we want them to be displayed in degrees N/S/E/W.
"""
lon = lon * (180.0 / np.pi)
lat = lat * (180.0 / np.pi)
lon = np.degrees(lon)
lat = np.degrees(lat)
if lat >= 0.0:
ns = 'N'
else:
Expand All @@ -294,8 +294,7 @@ def __init__(self, round_to=1.0):
self._round_to = round_to

def __call__(self, x, pos=None):
degrees = (x / np.pi) * 180.0
degrees = round(degrees / self._round_to) * self._round_to
degrees = round(np.degrees(x) / self._round_to) * self._round_to
# \u00b0 : degree symbol
return "%d\u00b0" % degrees

Expand Down Expand Up @@ -347,7 +346,7 @@ def set_longitude_grid_ends(self, degrees):
class -- it provides an interface to something that has no
analogy in the base Axes class.
"""
longitude_cap = degrees * (np.pi / 180.0)
longitude_cap = np.radians(degrees)
# Change the xaxis gridlines transform so that it draws from
# -degrees to degrees, rather than -pi to pi.
self._xaxis_pretransform \
Expand Down
9 changes: 4 additions & 5 deletions examples/api/custom_scale_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, axis, **kwargs):
thresh: The degree above which to crop the data.
"""
mscale.ScaleBase.__init__(self)
thresh = kwargs.pop("thresh", (85 / 180.0) * np.pi)
thresh = kwargs.pop("thresh", np.radians(85))
if thresh >= np.pi / 2.0:
raise ValueError("thresh must be less than pi/2")
self.thresh = thresh
Expand Down Expand Up @@ -72,11 +72,10 @@ def set_default_locators_and_formatters(self, axis):
class DegreeFormatter(Formatter):
def __call__(self, x, pos=None):
# \u00b0 : degree symbol
return "%d\u00b0" % ((x / np.pi) * 180.0)
return "%d\u00b0" % (np.degrees(x))

deg2rad = np.pi / 180.0
axis.set_major_locator(FixedLocator(
np.arange(-90, 90, 10) * deg2rad))
np.radians(np.arange(-90, 90, 10))))
axis.set_major_formatter(DegreeFormatter())
axis.set_minor_formatter(DegreeFormatter())

Expand Down Expand Up @@ -159,7 +158,7 @@ def inverted(self):
import matplotlib.pyplot as plt

t = np.arange(-180.0, 180.0, 0.1)
s = t / 360.0 * np.pi
s = np.radians(t)/2.

plt.plot(t, s, '-', lw=2)
plt.gca().set_yscale('mercator')
Expand Down
2 changes: 1 addition & 1 deletion examples/api/joinstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def plot_angle(ax, x, y, angle, style):
phi = angle/180*np.pi
phi = np.radians(angle)
xx = [x + .5, x, x + .5*np.cos(phi)]
yy = [y, y, y + .5*np.sin(phi)]
ax.plot(xx, yy, lw=8, color='blue', solid_joinstyle=style)
Expand Down
2 changes: 1 addition & 1 deletion examples/api/radar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _close_line(self, line):
line.set_data(x, y)

def set_varlabels(self, labels):
self.set_thetagrids(theta*180/np.pi, labels)
self.set_thetagrids(np.degrees(theta), labels)

def _gen_axes_patch(self):
return self.draw_patch()
Expand Down
4 changes: 2 additions & 2 deletions examples/api/sankey_demo_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def sankey(ax,

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

def add_input(path, gain, sign=1):
h = (gain / 2) * np.tan(inangle / 180. * np.pi) # Dip depth
h = (gain / 2) * np.tan(np.radians(inangle)) # Dip depth
move, (x, y) = path[-1] # Use last point as reference
if sign == 0: # First gain (horizontal)
path.extend([(Path.LINETO, [x - dx, y]),
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/tricontour_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
[-0.077, 0.990], [-0.059, 0.993]])
x = xy[:, 0]*180/3.14159
y = xy[:, 1]*180/3.14159
x = np.degrees(xy[:, 0])
y = np.degrees(xy[:, 1])
x0 = -5
y0 = 52
z = np.exp(-0.01*((x - x0)*(x - x0) + (y - y0)*(y - y0)))
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/triplot_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
[-0.077, 0.990], [-0.059, 0.993]])
x = xy[:, 0]*180/3.14159
y = xy[:, 1]*180/3.14159
x = np.degrees(xy[:, 0])
y = np.degrees(xy[:, 1])

triangles = np.asarray([
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],
Expand Down
2 changes: 1 addition & 1 deletion examples/units/ellipse_with_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
x = 0.5 * width * np.cos(theta)
y = 0.5 * height * np.sin(theta)

rtheta = angle*np.pi/180.
rtheta = np.radians(angle)
R = np.array([
[np.cos(rtheta), -np.sin(rtheta)],
[np.sin(rtheta), np.cos(rtheta)],
Expand Down