Created
February 27, 2018 19:55
-
-
Save jeongho/9a56be953f1b3cc2bb458eddd0f73094 to your computer and use it in GitHub Desktop.
Mandelbrot set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#https://matplotlib.org/examples/showcase/mandelbrot.html | |
#http://www.scipy-lectures.org/intro/numpy/auto_examples/plot_mandelbrot.html | |
""" | |
Mandelbrot set | |
============== | |
Compute the Mandelbrot fractal and plot it | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from numpy import newaxis | |
def compute_mandelbrot(N_max, some_threshold, nx, ny): | |
# A grid of c-values | |
x = np.linspace(-2, 1, nx) | |
y = np.linspace(-1.5, 1.5, ny) | |
c = x[:,newaxis] + 1j*y[newaxis,:] | |
# Mandelbrot iteration | |
z = c | |
for j in range(N_max): | |
z = z**2 + c | |
mandelbrot_set = (abs(z) < some_threshold) | |
return mandelbrot_set | |
mandelbrot_set = compute_mandelbrot(50, 50., 601, 401) | |
plt.imshow(mandelbrot_set.T, extent=[-2, 1, -1.5, 1.5]) | |
plt.gray() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment