File:Mpl example Mandelbrot set.svg

Summary

Description
English: The Mandelbrot set, plotted with Python and matplotlib. (Originally programmed for Rosetta Code.)
Date
Source Own work
Author Adrien F. Vincent
SVG development
InfoField
Source code
InfoField

Python code

##########
## Code for the figure
##########
import matplotlib.pyplot as plt
import numpy as np

from matplotlib.cm import prism as colormap

fig, ax = plt.subplots(figsize=(10, 10))

def m(a):
    z = 0
    for n in range(1, 100):
        z = z**2 + a
        if abs(z) > 2.0:
            return n
    return np.NaN

X = np.arange(-2.0, 0.8, 0.001)
Y = np.arange(-1.5, 1.5, 0.001)
Z = np.zeros((len(Y), len(X)))

for iy, y in enumerate(Y):
    print (iy, "of", len(Y))
    for ix, x in enumerate(X):
        Z[iy,ix] = m(x + 1j * y)

ax.imshow(Z, cmap=colormap, interpolation='none',
          extent=[X.min(), X.max(), Y.min(), Y.max()])

ax.set_xlabel("Re(c)")
ax.set_ylabel("Im(c)")

fig.savefig("mandelbrot_python.svg")
plt.show()
##########

Rationale: this work aims at providing a version of the previous work https://commons.wikimedia.org/wiki/File:Logarithmic_Spiral_Pylab.svg , done by Morn, with a source code that uses object-oriented matplotlib interface and without Python wildcard import.

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Mpl%20example%20Mandelbrot%20set.svg
Category:Self-published work Category:Mandelbrot sets (whole) Category:SVG fractals
Category:CC-BY-SA-4.0 Category:Mandelbrot sets (whole) Category:SVG fractals Category:SVG images with required raster graphics Category:Self-published work Category:Valid SVG created with Matplotlib code