title: Area of overlapping circles
body: <p>I have the following Python code to generate random circles in order to simulate Brownian motion. I need to find the total area of the small red circles so that I can compare it to the total area of a larger blue circle. Since the circles are generated randomly, many of them overlap making it difficult to find the area. I have read many other responses related to this question about pixel painting, etc. What is the best way to find the area of these circles? I do not want to modify the generation of the circles, I just need to find the total area of the red circles on the plot.</p>
  
  <p>The code to generate the circles I need is as follows (Python v. 2.7.6):</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  
  new_line = []
  new_angle = []
  x_c = [0]
  y_c = [0]
  x_real = []
  y_real = []
  xy_dist = []
  circ = []   
  range_value = 101
  
  for x in range(0,range_value):
      mu, sigma = 0, 1
      new_line = np.random.normal(mu, sigma, 1)
      new_angle = np.random.uniform(0, 360)*np.pi/180
      x_c.append(new_line*np.cos(new_angle))
      y_c.append(new_line*np.sin(new_angle))
  
  x_real = np.cumsum(x_c)
  y_real = np.cumsum(y_c)
  a = np.mean(x_real)
  b = np.mean(y_real)
  
  i = 0
  while i&lt;=range_value:
      xy_dist.append(np.sqrt((x_real[i]-a)**2+(y_real[i]-b)**2))
      i += 1
  
  circ_rad = max(xy_dist)
  small_rad = 0.2
  
  fig = plt.figure()
  ax = fig.add_subplot(1, 1, 1)
  circ1 = plt.Circle((a,b), radius=circ_rad+small_rad, color='b')
  ax.add_patch(circ1)
  
  j = 0
  while j&lt;=range_value:
      circ = plt.Circle((x_real[j], y_real[j]), radius=small_rad, color='r', fill=True)
      ax.add_patch(circ)
      j += 1
  
  plt.axis('auto')
  plt.show()
  </code></pre>