write a program than plots the mandelbrot set
- User
write a program than plots the mandelbrot set
- Assistant
Certainly! Here's an example of a Python program that plots the Mandelbrot set using the matplotlib library:
import numpy as np import matplotlib.pyplot as plt def mandelbrot(c, max_iter): z = c for n in range(max_iter): if abs(z) > 2: return n z = z*z + c return max_iter def plot_mandelbrot(xmin, xmax, ymin, ymax, width, height, max_iter): r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) pixels = np.zeros((width, height)) for i in range(width): for j in range(height): c = r1[i] + r2[j]*1j pixels[i, j] = mandelbrot(c, max_iter) plt.imshow(pixels.T, cmap='hot', extent=[xmin, xmax, ymin, ymax]) plt.show() plot_mandelbrot(-2.0, 1.0, -1.5, 1.5, 1000, 1000, 100)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.