<jupyter_start><jupyter_text>Spherical Voronoi Diagrams  Plot a sphere<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import proj3d
%matplotlib inline

u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)

x = np.outer(np.cos(u), np.sin(v))
y = np.outer(np.sin(u), np.sin(v))
z = np.outer(np.ones(np.size(u)), np.cos(v))    

fig = plt.figure()
ax = fig.add_subplot('111', projection='3d')
ax.plot_surface(x, y, z, rstride=5, cstride=5, color='y', alpha=0.1)<jupyter_output><empty_output><jupyter_text>Plot the generator points<jupyter_code># define a set of points on the sphere in any way you like
import helpers  # this just randomly generates some points
points = helpers.generate_random_array_spherical_generators(50,1, np.random.RandomState(117))

fig = plt.figure()
ax = fig.add_subplot('111', projection='3d')
ax.plot_surface(x, y, z, rstride=5, cstride=5, color='y', alpha=0.1)
ax.scatter(points[:,0], points[:,1], points[:,2])<jupyter_output><empty_output><jupyter_text>Plot the vertices<jupyter_code>from _spherical_voronoi import SphericalVoronoi   # this will be in scipy.spatial from 0.18. release
radius = 1
center = np.array([0,0,0])
sv = SphericalVoronoi(points, radius, center)

fig = plt.figure()
ax = fig.add_subplot('111', projection='3d')
ax.plot_surface(x, y, z, rstride=5, cstride=5, color='y', alpha=0.1)
ax.scatter(points[:,0], points[:,1], points[:,2])
ax.scatter(sv.vertices[:,0], sv.vertices[:,1], sv.vertices[:,2], color='r')<jupyter_output><empty_output><jupyter_text>Plot the regions<jupyter_code>import scipy
from matplotlib import colors
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

fig = plt.figure()
ax = fig.add_subplot('111', projection='3d')
ax.plot_surface(x, y, z, rstride=5, cstride=5, color='y', alpha=0.1)
ax.scatter(points[:,0], points[:,1], points[:,2])

sv.sort_vertices_of_regions()
# this is not yet completely accurate
for n in range(0, len(sv.regions)):
    region = sv.regions[n]
    ax.scatter(points[n, 0], points[n, 1], points[n, 2], c='b')
    random_color = colors.rgb2hex(scipy.rand(3))
    polygon = Poly3DCollection([sv.vertices[region]], alpha=1.0)
    polygon.set_color(random_color)
    ax.add_collection3d(polygon)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1634446397188049, 'fraction_numerical': 0.035588752196836555, 'mean_word_length': 6.4411764705882355, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '323519', 'license': 'MIT', 'n_tokens_mistral': 927, 'n_tokens_neox': 907, 'n_words': 185, 'path': 'examples/spherical_voronoi.ipynb', 'repo_name': 'niknow/pydata-london-2016-voronoi', 'size': '2276'}