Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. # install requirements
  2. # sudo pip install numpy matplotlib pyvoro
  3.  
  4. import pyvoro
  5. import numpy as np
  6. import matplotlib.pyplot as plt
  7.  
  8. points = np.array([[-74.0059, 40.7127], # NY
  9. [-118.25, 34.05], # LA
  10. [-87.684722, 41.836944], # Chicago
  11. [-79.4, 43.7], # Toronto
  12. [-96.796667, 32.775833], # Dallas-FortWorth
  13. [-122.416667, 37.783333], # San Francisco
  14. [-95.383056, 29.762778], # Houston
  15. [-80.208889, 25.775278], # Miami
  16. [-75.166667, 39.95], # Philadelphia
  17. [-84.39, 33.755], # Atlanta
  18. [77.016389, 38.904722] # DC
  19. ])
  20.  
  21. radii = np.array([20.63/5, # pop in millions
  22. 15.058/5, # divided to avoid problems
  23. 9.156/5,
  24. 6.456/5,
  25. 6.174/5,
  26. 5.929/5,
  27. 5.764/5, # Houston
  28. 5.764/5,
  29. 5.570/5,
  30. 5.015/5,
  31. 4.889/5 # DC
  32. ])
  33.  
  34. xlim = [-124, -71]
  35. ylim = [ 25 , 53]
  36.  
  37. def plotvor(cells, points, radii, xlim, ylim):
  38. plt.figure()
  39. plt.hold(True)
  40. plt.xlim(xlim)
  41. plt.ylim(ylim)
  42. for cell in cells:
  43. plt.scatter(cell["original"][0], cell["original"][1])
  44. vertices = np.array(cell["vertices"])
  45. vertices = np.concatenate((vertices,
  46. cell["vertices"][0].reshape((1,2))))
  47. plt.plot(vertices[:,0], vertices[:,1], 'b-')
  48. for point, radius in zip(points, radii):
  49. t = np.concatenate((np.arange(0, 2*np.pi, 0.1), np.array([0])))
  50. plt.plot(radius*np.cos(t)+point[0], radius*np.sin(t)+point[1])
  51. plt.show()
  52.  
  53. cells = pyvoro.compute_2d_voronoi(
  54. points,
  55. [xlim, ylim], # box size
  56. 0.5, # block size
  57. radii = radii)
  58.  
  59. plotvor(cells, points, radii, xlim, ylim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement