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 | |
Source code | 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:
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.