title: Colorize Voronoi Diagram
body: <p>I'm trying to colorize a Voronoi Diagram created using <a href="http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.spatial.Voronoi.html" rel="noreferrer"><code>scipy.spatial.Voronoi</code></a>. Here's my code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.spatial import Voronoi, voronoi_plot_2d
  
  # make up data points
  points = np.random.rand(15,2)
  
  # compute Voronoi tesselation
  vor = Voronoi(points)
  
  # plot
  voronoi_plot_2d(vor)
  
  # colorize
  for region in vor.regions:
      if not -1 in region:
          polygon = [vor.vertices[i] for i in region]
          plt.fill(*zip(*polygon))
  
  plt.show()
  </code></pre>
  
  <p>The resulting image:</p>
  
  <p><img src="https://i.stack.imgur.com/vmZpK.png" alt="Voronoi Diagram"></p>
  
  <p>As you can see some of the Voronoi regions at the border of the image are not colored. That is because some indices to the Voronoi vertices for these regions are set to <code>-1</code>, i.e., for those vertices outside the Voronoi diagram. According to the docs:</p>
  
  <blockquote>
    <p><em>regions:</em> (list of list of ints, shape (nregions, *)) Indices of the Voronoi vertices forming each Voronoi region. <strong>-1 indicates vertex outside the Voronoi diagram.</strong></p>
  </blockquote>
  
  <p>In order to colorize these regions as well, I've tried to just remove these "outside" vertices from the polygon, but that didn't work. I think, I need to fill in some points at the border of the image region, but I can't seem to figure out how to achieve this reasonably.</p>
  
  <p>Can anyone help?</p>