Guest User

Untitled

a guest
Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. def mandelbrot(c,maxiter):
  2. z = c
  3. for n in range(maxiter):
  4. if abs(z) > 2:
  5. return n
  6. z = z*z + c
  7. return 0
  8.  
  9. def julia (c,maxiter):
  10. z = 0
  11. c = complex(-0.1, 0.65)
  12. for n in range(maxiter):
  13. if abs(z) > 2:
  14. return n
  15. z = z*z + c
  16. return 0
  17.  
  18. def julia_set(xmin,xmax,ymin,ymax,width,height,maxiter):
  19. r1 = np.linspace(xmin, xmax, width)
  20. r2 = np.linspace(ymin, ymax, height)
  21. n3 = np.empty((width,height))
  22. for i in range(width):
  23. for j in range(height):
  24. n3[i,j] = julia(r1[i] + 1j*r2[j],maxiter)
  25. return (r1,r2,n3)
  26.  
  27. from matplotlib import pyplot as plt
  28. from matplotlib import colors
  29. %matplotlib inline
  30.  
  31. def julia_image(xmin,xmax,ymin,ymax,width=10,height=10,maxiter=100,cmap='hot'):
  32. dpi = 50
  33. img_width = dpi * width
  34. img_height = dpi * height
  35. x,y,z = julia_set(xmin,xmax,ymin,ymax,img_width,img_height,maxiter)
  36.  
  37. fig, ax = plt.subplots(figsize=(width, height),dpi=50)
  38. ticks = np.arange(0,img_width,3*dpi)
  39. x_ticks = xmin + (xmax-xmin)*ticks/img_width
  40. plt.xticks(ticks, x_ticks)
  41. y_ticks = ymin + (ymax-ymin)*ticks/img_width
  42. plt.yticks(ticks, y_ticks)
  43.  
  44. ax.imshow(z.T,cmap=cmap,origin='lower')
  45.  
  46. julia_image(-2.0,2.0,-3,3,cmap='afmhot')
Add Comment
Please, Sign In to add comment