From cb154e525732563e7795789fc29bacee669bfe17 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Tue, 18 Nov 2014 22:08:58 +0100 Subject: [PATCH 1/2] [examples] use np.radians/np.degrees where appropriate --- examples/animation/double_pendulum_animated.py | 2 +- examples/api/custom_projection_example.py | 9 ++++----- examples/api/custom_scale_example.py | 9 ++++----- examples/api/joinstyle.py | 2 +- examples/api/radar_chart.py | 2 +- examples/api/sankey_demo_old.py | 4 ++-- examples/pylab_examples/tricontour_demo.py | 4 ++-- examples/pylab_examples/triplot_demo.py | 4 ++-- examples/units/ellipse_with_units.py | 2 +- 9 files changed, 18 insertions(+), 20 deletions(-) diff --git a/examples/animation/double_pendulum_animated.py b/examples/animation/double_pendulum_animated.py index ee88fda82ce4..fe1d078cee28 100644 --- a/examples/animation/double_pendulum_animated.py +++ b/examples/animation/double_pendulum_animated.py @@ -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 diff --git a/examples/api/custom_projection_example.py b/examples/api/custom_projection_example.py index 3389b77a4a28..b5e0ed35dac6 100644 --- a/examples/api/custom_projection_example.py +++ b/examples/api/custom_projection_example.py @@ -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: @@ -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 @@ -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 \ diff --git a/examples/api/custom_scale_example.py b/examples/api/custom_scale_example.py index 9bb94e402841..57e395dc1b7e 100644 --- a/examples/api/custom_scale_example.py +++ b/examples/api/custom_scale_example.py @@ -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 @@ -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()) @@ -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.radius(t)/2. plt.plot(t, s, '-', lw=2) plt.gca().set_yscale('mercator') diff --git a/examples/api/joinstyle.py b/examples/api/joinstyle.py index b4e3c5e0dfd2..f0a8a252ff22 100644 --- a/examples/api/joinstyle.py +++ b/examples/api/joinstyle.py @@ -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) diff --git a/examples/api/radar_chart.py b/examples/api/radar_chart.py index 7f8d24b1cb76..81920764a8e5 100644 --- a/examples/api/radar_chart.py +++ b/examples/api/radar_chart.py @@ -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() diff --git a/examples/api/sankey_demo_old.py b/examples/api/sankey_demo_old.py index 90494e5a1ff8..dee4ea220379 100755 --- a/examples/api/sankey_demo_old.py +++ b/examples/api/sankey_demo_old.py @@ -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]), @@ -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]), diff --git a/examples/pylab_examples/tricontour_demo.py b/examples/pylab_examples/tricontour_demo.py index c1126e296ea5..40313d7bc4f2 100644 --- a/examples/pylab_examples/tricontour_demo.py +++ b/examples/pylab_examples/tricontour_demo.py @@ -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))) diff --git a/examples/pylab_examples/triplot_demo.py b/examples/pylab_examples/triplot_demo.py index 84dcb4a76b02..a524547291b0 100644 --- a/examples/pylab_examples/triplot_demo.py +++ b/examples/pylab_examples/triplot_demo.py @@ -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], diff --git a/examples/units/ellipse_with_units.py b/examples/units/ellipse_with_units.py index c810058e63ba..2127d6c0323a 100644 --- a/examples/units/ellipse_with_units.py +++ b/examples/units/ellipse_with_units.py @@ -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)], From 1d904e31ba7343529e4bbb3d1ed7465181badaff Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Tue, 18 Nov 2014 22:23:20 +0100 Subject: [PATCH 2/2] fix typo Signed-off-by: Thomas Hisch --- examples/api/custom_scale_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/api/custom_scale_example.py b/examples/api/custom_scale_example.py index 57e395dc1b7e..92ca2a784373 100644 --- a/examples/api/custom_scale_example.py +++ b/examples/api/custom_scale_example.py @@ -158,7 +158,7 @@ def inverted(self): import matplotlib.pyplot as plt t = np.arange(-180.0, 180.0, 0.1) - s = np.radius(t)/2. + s = np.radians(t)/2. plt.plot(t, s, '-', lw=2) plt.gca().set_yscale('mercator')