diff options
author | Melissa Weber Mendonça <melissawm@gmail.com> | 2021-04-04 16:24:43 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-04 21:24:43 +0200 |
commit | 036f6c68f849c6659fef9b91aaafa7e447286c5c (patch) | |
tree | 1e60abc32a2b7f362924b3d7d81b20ca3fdbca81 | |
parent | 623bc1fae1d47df24e7f1e29321d0c0ba2771ce0 (diff) | |
download | numpy-036f6c68f849c6659fef9b91aaafa7e447286c5c.tar.gz |
DOC: Simplifies Mandelbrot set plot in Quickstart guide (#18712)
Closes gh-18409
-rw-r--r-- | doc/source/user/quickstart.rst | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/doc/source/user/quickstart.rst b/doc/source/user/quickstart.rst index 28262c89e..9f3d6a040 100644 --- a/doc/source/user/quickstart.rst +++ b/doc/source/user/quickstart.rst @@ -1254,19 +1254,21 @@ set <https://en.wikipedia.org/wiki/Mandelbrot_set>`__: >>> import numpy as np >>> import matplotlib.pyplot as plt - >>> def mandelbrot(h, w, maxit=20): + >>> def mandelbrot(h, w, maxit=20, r=2): ... """Returns an image of the Mandelbrot fractal of size (h,w).""" - ... y, x = np.ogrid[-1.4:1.4:h*1j, -2:0.8:w*1j] - ... c = x + y * 1j - ... z = c + ... x = np.linspace(-2.5, 1.5, 4*h+1) + ... y = np.linspace(-1.5, 1.5, 3*w+1) + ... A, B = np.meshgrid(x, y) + ... C = A + B*1j + ... z = np.zeros_like(C) ... divtime = maxit + np.zeros(z.shape, dtype=int) ... ... for i in range(maxit): - ... z = z**2 + c - ... diverge = z * np.conj(z) > 2**2 # who is diverging + ... z = z**2 + C + ... diverge = abs(z) > r # who is diverging ... div_now = diverge & (divtime == maxit) # who is diverging now ... divtime[div_now] = i # note when - ... z[diverge] = 2 # avoid diverging too much + ... z[diverge] = r # avoid diverging too much ... ... return divtime >>> plt.imshow(mandelbrot(400, 400)) |