File:Mandelbrot set, plotted with Matplotlib.svg

Summary

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

Python code

Source code
from pylab import *
from numpy import NaN

xmin, xmax, ymin, ymax = -2, 0.8, -1.5, 1.5
max_it = 100    # maximum number of iterations
px     = 3000	# vertical lines
res    = (ymax - ymin) / px   # grid resolution

figure(figsize = (10, 10))

def m(c):
	z = 0
	for n in range(1, max_it + 1):
		z = z**2 + c
		if abs(z) > 2:
			return n
	return NaN

X = arange(xmin, xmax + res, res)
Y = arange(ymin, ymax + res, res)
Z = zeros((len(Y), len(X)))

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

save("mandel", Z)	# save array to file

imshow(Z, cmap = plt.cm.prism, interpolation = 'none',
  extent = (X.min(), X.max(), Y.min(), Y.max()))
xlabel("Re(c)")
ylabel("Im(c)")
savefig("mandelbrot_python.svg")
show()
Category:Mandelbrot sets (whole) Category:Images with Python source code Category:SVG fractals

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Category:CC-Zero#Mandelbrot%20set,%20plotted%20with%20Matplotlib.svg
Category:Self-published work
Annotations
InfoField
This image is annotated: View the annotations at Commons
Category:CC-Zero Category:Images with Python source code Category:Images with annotations Category:Mandelbrot sets (whole) Category:SVG fractals Category:Self-published work Category:Valid SVG created with Matplotlib code