Created
May 28, 2017 11:32
-
-
Save yuyyuyu/2cf41f66aa3a1d2ae4d25cb244a87cc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.stats | |
import scipy.spatial | |
from numpy.random import RandomState | |
import matplotlib.pyplot as plt | |
rv=RandomState(123456789) | |
locations=rv.randint(0,511,size=(2,128)) | |
#voronoiSet | |
voronoiSet=scipy.spatial.Voronoi(locations.T) | |
scipy.spatial.voronoi_plot_2d(voronoiSet,show_points=True,show_vertices=False) | |
plt.savefig('voronoi.png') | |
plt.show() | |
#triangulation | |
triangulation=scipy.spatial.Delaunay(locations.T) | |
assim_vertex=lambda index: triangulation.points[index] | |
triangle_set=map(assim_vertex,triangulation.vertices) | |
plt.triplot(locations[1],locations[0],triangles=triangle_set,color='r') | |
plt.scatter(locations[1],locations[0]) | |
plt.savefig('triangular.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment