Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to plot a Voronoi tessellation directly from a previous Delaunay triangulation?

I have a small Python code plotting a small Delaunay triangulation:

import numpy as np 
import matplotlib.pyplot as plt 
from scipy.spatial import Delaunay 

points = np.array([[0, 0], 
                   [1, 0], 
                   [0.5, 0.5],
                   [1 , 0.5]])
tri = Delaunay(points) 
fig, ax = plt.subplots(figsize=(8, 4))
ax.set_aspect('equal', 'box')
plt.triplot(points[:,0], points[:,1], tri.simplices.copy()) 
plt.plot(points[:,0], points[:,1], 'o') 
plt.show() 

Do you know if it’s now possible in Python to directly superimpose on the previous plot the corresponding Voronoi tessellation?

I am using Python ‘3.9.7’ and a Matplotlib ‘3.8.4’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the delauney_plot_2d and voronoi_plot_2d helper functions and just pass the Matplotlib axes object to them both. E.g.,

import numpy as np 
import matplotlib.pyplot as plt 
from scipy.spatial import Delaunay, Voronoi, voronoi_plot_2d, delaunay_plot_2d

points = np.array([[0, 0], 
                   [1, 0], 
                   [0.5, 0.5],
                   [1 , 0.5]])
tri = Delaunay(points) 
fig, ax = plt.subplots(figsize=(8, 4))

vor = Voronoi(points)

_ = delaunay_plot_2d(tri, ax=ax)
_ = voronoi_plot_2d(vor, ax=ax)

ax.set_aspect('equal', 'box')

enter image description here

You can customise the points/line styles/etc in those functions.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading