Advertisement
bolverk

scipy_voronoi_example

May 13th, 2015
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. def main():
  2.  
  3.     from scipy.spatial import Voronoi
  4.     import numpy
  5.     import pylab
  6.  
  7.     numpy.random.seed(1)
  8.     vor = Voronoi(numpy.random.random((20,2)))
  9.  
  10.     print(vor.ridge_points.T)
  11.     print(vor.ridge_vertices)
  12.  
  13.     pylab.plot(vor.points.T[0],
  14.                vor.points.T[1],'.')
  15.     pylab.plot(vor.vertices.T[0],
  16.                vor.vertices.T[1],'.')
  17.     for pair in vor.ridge_points:
  18.         if pair[0]>=0 and pair[1]>=0:
  19.             pylab.plot([vor.points.T[0][pair[0]],vor.points.T[0][pair[1]]],
  20.                        [vor.points.T[1][pair[0]],vor.points.T[1][pair[1]]],'k')
  21.     for pair in vor.ridge_vertices:
  22.         if pair[0]>=0 and pair[1]>=0:
  23.             pylab.plot([vor.vertices.T[0][pair[0]],vor.vertices.T[0][pair[1]]],
  24.                        [vor.vertices.T[1][pair[0]],vor.vertices.T[1][pair[1]]],'r')
  25.                          
  26.     pylab.xlim((0,1))
  27.     pylab.ylim((0,1))
  28.     pylab.show()
  29.  
  30. if __name__ == '__main__':
  31.  
  32.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement