是否可以直接根据之前的 Delaunay 三角剖分绘制 Voronoi 曲面细分?

问题描述 投票:0回答:1

我有一个小的 Python 代码,绘制了一个小的 Delaunay 三角剖分:

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() 

你知道现在 Python 中是否可以直接将相应的 Voronoi 曲面细分叠加到上一张图上吗?

我正在使用 Python '3.9.7' 和 Matplotlib '3.8.4'

python-3.x matplotlib voronoi delaunay
1个回答
0
投票

您可以使用

delauney_plot_2d
voronoi_plot_2d
辅助函数,只需将 Matplotlib 轴对象传递给它们即可。例如,

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

您可以在这些功能中自定义点/线样式等。

© www.soinside.com 2019 - 2024. All rights reserved.