Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # install requirements
- # sudo pip install numpy matplotlib pyvoro
- import pyvoro
- import numpy as np
- import matplotlib.pyplot as plt
- points = np.array([[-74.0059, 40.7127], # NY
- [-118.25, 34.05], # LA
- [-87.684722, 41.836944], # Chicago
- [-79.4, 43.7], # Toronto
- [-96.796667, 32.775833], # Dallas-FortWorth
- [-122.416667, 37.783333], # San Francisco
- [-95.383056, 29.762778], # Houston
- [-80.208889, 25.775278], # Miami
- [-75.166667, 39.95], # Philadelphia
- [-84.39, 33.755], # Atlanta
- [77.016389, 38.904722] # DC
- ])
- radii = np.array([20.63/5, # pop in millions
- 15.058/5, # divided to avoid problems
- 9.156/5,
- 6.456/5,
- 6.174/5,
- 5.929/5,
- 5.764/5, # Houston
- 5.764/5,
- 5.570/5,
- 5.015/5,
- 4.889/5 # DC
- ])
- xlim = [-124, -71]
- ylim = [ 25 , 53]
- def plotvor(cells, points, radii, xlim, ylim):
- plt.figure()
- plt.hold(True)
- plt.xlim(xlim)
- plt.ylim(ylim)
- for cell in cells:
- plt.scatter(cell["original"][0], cell["original"][1])
- vertices = np.array(cell["vertices"])
- vertices = np.concatenate((vertices,
- cell["vertices"][0].reshape((1,2))))
- plt.plot(vertices[:,0], vertices[:,1], 'b-')
- for point, radius in zip(points, radii):
- t = np.concatenate((np.arange(0, 2*np.pi, 0.1), np.array([0])))
- plt.plot(radius*np.cos(t)+point[0], radius*np.sin(t)+point[1])
- plt.show()
- cells = pyvoro.compute_2d_voronoi(
- points,
- [xlim, ylim], # box size
- 0.5, # block size
- radii = radii)
- plotvor(cells, points, radii, xlim, ylim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement