我有一个小的 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'
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')
您可以在这些功能中自定义点/线样式等。