Python:情节在scipy情节之上? (voronoi)
Python: plot on top of scipy plot? (voronoi)
如何在 voronoi 图(scipy 图)上绘图?请注意,我的问题与 here 略有不同,他们解释了如何 color voronoi plot
比如,假设我还有一些积分
points = np.array([[1,2], [3,4], [5,6], [7,8]])
在第一个 voronoi 图之后。我想将它们添加到现有的地块中。我该怎么做?
我指的 voronoi 图是 scipy.spatial.voronoi_plot_2d()
我认为您可以像这样简单地重用图:
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import voronoi_plot_2d, Voronoi
points = np.array([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]])
v = Voronoi(points)
voronoi_plot_2d(v)
p2 = [[0.25, 1], [1, 0.75], [1.75, 0.25], [1.75, 1.75]]
x, y = zip(*p2)
plt.scatter(x, y, color='r')
plt.show()
我遇到了同样的问题。这是一个可以明确执行的函数。注意:它在无穷远处丢弃点。
那里有很多 space 需要改进的地方;欢迎编辑。
def plot_vor_edges(vor, ax=None):
if ax is None:
ax = plt.axes()
ver = vor.vertices
for reg in vor.regions:
# Remove vertices at infinity
if len(reg)>=1:
if -1 in reg:
reg = np.roll(reg, -reg.index(-1))
reg = [x for x in reg if x != -1]
regionX = ver[reg, 1]
regionY = ver[reg, 0]
else:
regionX = ver[reg + [reg[0]], 1]
regionY = ver[reg + [reg[0]], 0]
ax.plot(regionX, regionY, '-k', linewidth=0.5)
else:
continue
如何在 voronoi 图(scipy 图)上绘图?请注意,我的问题与 here 略有不同,他们解释了如何 color voronoi plot
比如,假设我还有一些积分
points = np.array([[1,2], [3,4], [5,6], [7,8]])
在第一个 voronoi 图之后。我想将它们添加到现有的地块中。我该怎么做?
我指的 voronoi 图是 scipy.spatial.voronoi_plot_2d()
我认为您可以像这样简单地重用图:
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import voronoi_plot_2d, Voronoi
points = np.array([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]])
v = Voronoi(points)
voronoi_plot_2d(v)
p2 = [[0.25, 1], [1, 0.75], [1.75, 0.25], [1.75, 1.75]]
x, y = zip(*p2)
plt.scatter(x, y, color='r')
plt.show()
我遇到了同样的问题。这是一个可以明确执行的函数。注意:它在无穷远处丢弃点。 那里有很多 space 需要改进的地方;欢迎编辑。
def plot_vor_edges(vor, ax=None):
if ax is None:
ax = plt.axes()
ver = vor.vertices
for reg in vor.regions:
# Remove vertices at infinity
if len(reg)>=1:
if -1 in reg:
reg = np.roll(reg, -reg.index(-1))
reg = [x for x in reg if x != -1]
regionX = ver[reg, 1]
regionY = ver[reg, 0]
else:
regionX = ver[reg + [reg[0]], 1]
regionY = ver[reg + [reg[0]], 0]
ax.plot(regionX, regionY, '-k', linewidth=0.5)
else:
continue