Python:Plot scipy 在 voronoi 图上绘制
Python:Plot scipy plot on top of voronoi diagram
我正在尝试在 scipy 绘图之上绘图。使用了 [this solution] () 但仍然无法获得单图。谁能帮忙?提前致谢...
示例图如下,并试图重叠它们:Voronoi Diagram and Scatter Plot
vor = Voronoi( points )
voronoi_plot_2d(vor)
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('Junctions.csv','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
x.append((row[0]))
y.append((row[1]))
fig,ax = plt.subplots()
ax.scatter(x,y,s=5,color='r')
for i, txt in enumerate(n):
ax.annotate(txt, (x[i], y[i]), size = 6)
plt.show()
您可以将相同的轴发送到 Voronoi 图和散点图。 voronoi_plot_2d
函数还包括轴作为参数:
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import voronoi_plot_2d, Voronoi, KDTree
x = [.22, .2, .4, .44, .42, .61, .17, .2, .63, .66]
y = [.21, .43, .23, .41, .42, .31, .2, .17, .62, .65]
points = np.array([[.1, .1], [.12, .44], [.11, .7], [.39, .09], [.41, .5], [.7, .14], [.71, .65]])
vor = Voronoi(points)
tree = KDTree(points)
locs, ids = tree.query(list(zip(x,y)))
fig,ax = plt.subplots(1,1)
voronoi_plot_2d(vor,ax)
ax.scatter(x,y,s=20,color='r')
for i in range(0,len(x)):
ax.annotate(ids[i], (x[i], y[i]), size = 10)
plt.show()
使用这四行(和一些任意数据)生成此图:
我正在尝试在 scipy 绘图之上绘图。使用了 [this solution] (
vor = Voronoi( points )
voronoi_plot_2d(vor)
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('Junctions.csv','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
x.append((row[0]))
y.append((row[1]))
fig,ax = plt.subplots()
ax.scatter(x,y,s=5,color='r')
for i, txt in enumerate(n):
ax.annotate(txt, (x[i], y[i]), size = 6)
plt.show()
您可以将相同的轴发送到 Voronoi 图和散点图。 voronoi_plot_2d
函数还包括轴作为参数:
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import voronoi_plot_2d, Voronoi, KDTree
x = [.22, .2, .4, .44, .42, .61, .17, .2, .63, .66]
y = [.21, .43, .23, .41, .42, .31, .2, .17, .62, .65]
points = np.array([[.1, .1], [.12, .44], [.11, .7], [.39, .09], [.41, .5], [.7, .14], [.71, .65]])
vor = Voronoi(points)
tree = KDTree(points)
locs, ids = tree.query(list(zip(x,y)))
fig,ax = plt.subplots(1,1)
voronoi_plot_2d(vor,ax)
ax.scatter(x,y,s=20,color='r')
for i in range(0,len(x)):
ax.annotate(ids[i], (x[i], y[i]), size = 10)
plt.show()
使用这四行(和一些任意数据)生成此图: