-2

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. Thank you!!

1 Answers1

0

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:

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()
cdlane
  • 40,441
  • 5
  • 32
  • 81