[英]Zooming in on mandelbrot in python
This is my current code which is currently creating two images instead of zooming in. How would I change the code to create on fractal that zooms in its self?这是我当前的代码,目前正在创建两个图像而不是放大。我将如何更改代码以在自身放大的分形上创建? Thank you so much!太感谢了!
import numpy as np
import matplotlib.pyplot as plt
SIZE = 50
def testpoint(c, maxreps):
z = 0
reps = 0
while abs(z) < 2 and reps < maxreps:
z = z ** 2 + c
reps += 1
frac = float(reps) / float(maxreps)
return frac
def compute_mandelbrot(N_max, xmin, xmax, ymin, ymax, nx, ny):
# A grid of c-values
x = np.linspace(xmin, xmax, nx)
y = np.linspace(ymax, ymin, ny)
z = np.zeros([nx, ny])
for a in range(nx):
for b in range(ny):
z[a, b]=testpoint(complex(x[a], y[b]), N_max)
return z
if __name__ == '__main__':
xmin = -1.5
xmax = 0.5
ymin = -1
ymax = 1
pts = 800
mandelbrot_set = compute_mandelbrot(50, xmin, xmax, ymin, ymax, pts, pts)
plt.imshow(mandelbrot_set.T, extent=[xmin, xmax, ymin,ymax], cmap = plt.cm.rainbow)
plt.colorbar()
plt.show()
xmin = -1.0
xmax = 0.1
ymin = -0.5
ymax = 0.2
pts = 800
mandelbrot_set2 = compute_mandelbrot(50, xmin, xmax, ymin, ymax, pts, pts)
plt.imshow(mandelbrot_set2.T, extent=[xmin, xmax, ymin, ymax], cmap = plt.cm.rainbow)
plt.show()
I am trying to get the mandelbrot to zoom in on one image.我试图让 mandelbrot 放大一张图片。 Thank you!!谢谢!!
There seems to be a bit of mystery involved with plt.pause()
-- give the following a try as I believe it does what you describe: plt.pause()
似乎有点神秘 - 尝试以下操作,因为我相信它会按照您的描述进行操作:
if __name__ == '__main__':
xmin, xmax = -1.5, 0.5
ymin, ymax = -1, 1
pts = 800
mandelbrot_set = compute_mandelbrot(50, xmin, xmax, ymin, ymax, pts, pts)
plt.imshow(mandelbrot_set.T, extent=[xmin, xmax, ymin, ymax], cmap=plt.cm.rainbow)
plt.colorbar()
plt.show(block=False)
plt.pause(0.01)
xmin, xmax = -1.0, 0.1
ymin, ymax = -0.5, 0.2
pts = 800
mandelbrot_set2 = compute_mandelbrot(50, xmin, xmax, ymin, ymax, pts, pts)
plt.clf()
plt.imshow(mandelbrot_set2.T, extent=[xmin, xmax, ymin, ymax], cmap=plt.cm.rainbow)
plt.colorbar()
plt.pause(0.01)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.