title: displaying Mandelbrot set in python using matplotlib.pyplot and numpy
body: <p>I am trying to get a plot of a Mandelbrot set and having trouble plotting the expected plot. </p>
  
  <p>As I understand, the Mandelbrot set is made up of values c, which would converge if are iterated through the following equation z = z**2 + c. I used the initial value of z = 0. </p>
  
  <p>Initially, I was getting a straight line. I look for solutions online to see where I went wrong. Using the following link in particular, I attempted to improve my code:</p>
  
  <p><a href="https://scipy-lectures.org/intro/numpy/auto_examples/plot_mandelbrot.html" rel="nofollow noreferrer">https://scipy-lectures.org/intro/numpy/auto_examples/plot_mandelbrot.html</a></p>
  
  <p>Here is my improved code. I don't really understand the reason of using np.newaxis and why I am plotting the final z values that converge. Am I misunderstanding the definition of the Mandelbrot set? </p>
  
  <pre><code># initial values 
  loop = 50 # number of interations
  div = 600 # divisions
  # all possible values of c
  c = np.linspace(-2,2,div)[:,np.newaxis] + 1j*np.linspace(-2,2,div)[np.newaxis,:] 
  z = 0 
  for n in range(0,loop):
        z = z**2 + c
  
  plt.rcParams['figure.figsize'] = [12, 7.5]
  z = z[abs(z) &lt; 2] # removing z values that diverge 
  plt.scatter(z.real, z.imag, color = "black" ) # plotting points
  plt.xlabel("Real")
  plt.ylabel("i (imaginary)")
  plt.xlim(-2,2)
  plt.ylim(-1.5,1.5)
  plt.savefig("plot.png")
  plt.show()
  </code></pre>
  
  <p>and got the following image, which looks closer to the Mandelbrot set than anything I got so far. But it looks more of a starfish with scattered dots around it. 
  <a href="https://i.stack.imgur.com/1fJrw.png" rel="nofollow noreferrer">Image</a></p>
  
  <p>For reference, here is my initial code before improvement:</p>
  
  <pre><code># initial values 
  loop = 50
  div = 50
  clist = np.linspace(-2,2,div) + 1j*np.linspace(-1.5,1.5,div) # range of c values 
  all_results = []
  
  for c in clist: # for each value of c
      z = 0 # starting point
      for a in range(0,loop): 
          negative = 0 # unstable
  
          z = z**2 + c 
  
          if np.abs(z) &gt; 2: 
              negative +=1
          if negative &gt; 2: 
              break
  
      if negative == 0:
          all_results.append([c,"blue"]) #converging
      else:
          all_results.append([c,"black"]) # not converging
  </code></pre>