From 160f5f4e7403912bca36ee35f717038a8709f85f Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 19 Jan 2019 19:01:54 +0100 Subject: [PATCH] Avoid triggering warnings in mandelbrot example. ... namely ``` examples/showcase/mandelbrot.py:17: DeprecationWarning: object of type cannot be safely interpreted as an integer. X = np.linspace(xmin, xmax, xn).astype(np.float32) examples/showcase/mandelbrot.py:18: DeprecationWarning: object of type cannot be safely interpreted as an integer. Y = np.linspace(ymin, ymax, yn).astype(np.float32) ``` plus some minor cleanups. --- examples/showcase/mandelbrot.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/showcase/mandelbrot.py b/examples/showcase/mandelbrot.py index 3e19d9d644b9..b31e9e34ca81 100644 --- a/examples/showcase/mandelbrot.py +++ b/examples/showcase/mandelbrot.py @@ -33,11 +33,11 @@ def mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0): from matplotlib import colors import matplotlib.pyplot as plt - xmin, xmax, xn = -2.25, +0.75, 3000/2 - ymin, ymax, yn = -1.25, +1.25, 2500/2 + xmin, xmax, xn = -2.25, +0.75, 3000 // 2 + ymin, ymax, yn = -1.25, +1.25, 2500 // 2 maxiter = 200 horizon = 2.0 ** 40 - log_horizon = np.log(np.log(horizon))/np.log(2) + log_horizon = np.log2(np.log(horizon)) Z, N = mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon) # Normalized recount as explained in: @@ -47,15 +47,13 @@ def mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0): # This line will generate warnings for null values but it is faster to # process them afterwards using the nan_to_num with np.errstate(invalid='ignore'): - M = np.nan_to_num(N + 1 - - np.log(np.log(abs(Z)))/np.log(2) + - log_horizon) + M = np.nan_to_num(N + 1 - np.log2(np.log(abs(Z))) + log_horizon) dpi = 72 width = 10 height = 10*yn/xn fig = plt.figure(figsize=(width, height), dpi=dpi) - ax = fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False, aspect=1) + ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) # Shaded rendering light = colors.LightSource(azdeg=315, altdeg=10)