import numpy as np
from scipy.spatial import Voronoi, voronoi_plot_2d
import matplotlib.pyplot as plt

points = [[1,8], [4,5], [8,6], [4,3]] # np.random.rand(20, 2)

vor = Voronoi(points)
colors = plt.cm.tab20(np.arange(len(vor.regions)))

fig, ax = plt.subplots()
voronoi_plot_2d(vor, ax=ax, show_vertices=False, line_colors='k', line_width=2, line_alpha=0.6)


for region_index, region in enumerate(vor.regions):
    if not -1 in region and len(region) > 0:  # Vérifier si la région est finie
        polygon = [vor.vertices[i] for i in region]
        ax.fill(*zip(*polygon), color=colors[region_index], alpha=0.3)

# Ajouter les points d'origine
#ax.plot(points[:, 0], points[:, 1], 'o', markersize=1)

# Optionnel : ajuster les limites de la figure pour mieux voir le pavage
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)

plt.show()
