我有大约3000个点和6000条边,数据格式如下:
points = numpy.array([1,2],[4,5],[2,7],[3,9],[9,2])
edges = numpy.array([0,1],[3,4],[3,2],[2,4])
这里的边缘是指向点的索引,因此每条边的起始和结束坐标如下:
points[edges]
我正在寻找更快、更好的方法来绘制它们。目前我有以下代码:
from matplotlib import pyplot as plt
x = points[:,0].flatten()
y = points[:,1].flatten()
plt.plot(x[edges.T], y[edges.T], 'y-') # Edges
plt.plot(x, y, 'ro') # Points
plt.savefig('figure.png')
我了解到lineCollections,但是不确定如何使用它们。有没有一种更直接使用我的数据的方法?这里的瓶颈是什么?
以下是更真实的测试数据,绘图时间约为132秒:
points = numpy.random.randint(0, 100, (3000, 2))
edges = numpy.random.randint(0, 3000, (6000, 2))