import matplotlib.pyplot as plt from random import random def mandelbrot(n): for i in range(n): c=complex(4*random()-2,4*random()-2) z=0 k=0 while abs(z)<2 and k<50: z=z**2+c k=k+1 if k==50: plt.plot(c.real,c.imag,"rx",ms=0.5) plt.xlim=(-2,2) plt.ylim=(-2,2) ax=plt.gca() ax.spines["bottom"].set_position(("data",0)) ax.spines["left"].set_position(("data",0)) plt.show()