Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e473de

Browse files
anntzertacaswell
authored andcommitted
Avoid triggering warnings in mandelbrot example. (#13226)
... namely ``` examples/showcase/mandelbrot.py:17: DeprecationWarning: object of type <class 'float'> 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 <class 'float'> cannot be safely interpreted as an integer. Y = np.linspace(ymin, ymax, yn).astype(np.float32) ``` plus some minor cleanups.
1 parent 6f0a313 commit 4e473de

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

examples/showcase/mandelbrot.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0):
3333
from matplotlib import colors
3434
import matplotlib.pyplot as plt
3535

36-
xmin, xmax, xn = -2.25, +0.75, 3000/2
37-
ymin, ymax, yn = -1.25, +1.25, 2500/2
36+
xmin, xmax, xn = -2.25, +0.75, 3000 // 2
37+
ymin, ymax, yn = -1.25, +1.25, 2500 // 2
3838
maxiter = 200
3939
horizon = 2.0 ** 40
40-
log_horizon = np.log(np.log(horizon))/np.log(2)
40+
log_horizon = np.log2(np.log(horizon))
4141
Z, N = mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon)
4242

4343
# Normalized recount as explained in:
@@ -47,15 +47,13 @@ def mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0):
4747
# This line will generate warnings for null values but it is faster to
4848
# process them afterwards using the nan_to_num
4949
with np.errstate(invalid='ignore'):
50-
M = np.nan_to_num(N + 1 -
51-
np.log(np.log(abs(Z)))/np.log(2) +
52-
log_horizon)
50+
M = np.nan_to_num(N + 1 - np.log2(np.log(abs(Z))) + log_horizon)
5351

5452
dpi = 72
5553
width = 10
5654
height = 10*yn/xn
5755
fig = plt.figure(figsize=(width, height), dpi=dpi)
58-
ax = fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False, aspect=1)
56+
ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1)
5957

6058
# Shaded rendering
6159
light = colors.LightSource(azdeg=315, altdeg=10)

0 commit comments

Comments
 (0)