.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fractals_chaos/mandelbrot_julia/plot_02_mandelbrot_set.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_fractals_chaos_mandelbrot_julia_plot_02_mandelbrot_set.py: The Mandelbrot set ======================== Colours every parameter :math:`c` by how quickly the orbit of :math:`z_0 = 0` under :math:`z \mapsto z^2 + c` escapes. The black region, the Mandelbrot set, is the set of :math:`c` whose orbit stays bounded -- equivalently, whose Julia set is connected. Zooming into its boundary reveals ever finer detail, including small copies of the whole set. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python import matplotlib.pyplot as plt from mathematicskit.fractals_chaos import mandelbrot_set from mathematicskit.fractals_chaos.visualizers.plots import plot_escape_time .. GENERATED FROM PYTHON SOURCE LINES 20-22 The whole set ------------- .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python mandelbrot = mandelbrot_set(resolution=400, max_iter=200) ax = plot_escape_time(mandelbrot) ax.set_title("Mandelbrot set") .. image-sg:: /api/gallery/fractals_chaos/mandelbrot_julia/images/sphx_glr_plot_02_mandelbrot_set_001.png :alt: Mandelbrot set :srcset: /api/gallery/fractals_chaos/mandelbrot_julia/images/sphx_glr_plot_02_mandelbrot_set_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'Mandelbrot set') .. GENERATED FROM PYTHON SOURCE LINES 28-33 Zooming into the boundary ------------------------- Near :math:`c \approx -1.77` on the real axis, a small copy of the Mandelbrot set sits inside the boundary's filaments. .. GENERATED FROM PYTHON SOURCE LINES 33-43 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4.5)) seahorse = mandelbrot_set(extent=(-0.80, -0.70, 0.05, 0.15), resolution=300, max_iter=400) plot_escape_time(seahorse, ax=axes[0], cmap="twilight") axes[0].set_title("Seahorse valley") minibrot = mandelbrot_set(extent=(-1.80, -1.74, -0.03, 0.03), resolution=300, max_iter=400) plot_escape_time(minibrot, ax=axes[1], cmap="twilight") axes[1].set_title("A small copy near c = -1.77") fig.tight_layout() .. image-sg:: /api/gallery/fractals_chaos/mandelbrot_julia/images/sphx_glr_plot_02_mandelbrot_set_002.png :alt: Seahorse valley, A small copy near c = -1.77 :srcset: /api/gallery/fractals_chaos/mandelbrot_julia/images/sphx_glr_plot_02_mandelbrot_set_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 44-49 Membership check ---------------- :math:`c=-1` and :math:`c=0.25` lie in the set (bounded orbits); :math:`c = 0.3` and :math:`c = 1` do not. .. GENERATED FROM PYTHON SOURCE LINES 49-55 .. code-block:: Python for c in (-1.0, 0.25, 0.3, 1.0): z, steps = 0.0, 0 while abs(z) <= 2.0 and steps < 1000: z, steps = z * z + c, steps + 1 print(f"c = {c:5.2f}: {'bounded (in the set)' if abs(z) <= 2.0 else f'escapes after {steps} steps'}") .. rst-class:: sphx-glr-script-out .. code-block:: none c = -1.00: bounded (in the set) c = 0.25: bounded (in the set) c = 0.30: escapes after 12 steps c = 1.00: escapes after 3 steps .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.227 seconds) .. _sphx_glr_download_api_gallery_fractals_chaos_mandelbrot_julia_plot_02_mandelbrot_set.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_mandelbrot_set.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_mandelbrot_set.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_mandelbrot_set.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_