我有这种类型的格式的一些点(约3000)和边缘(6000):绘制大量的点和边缘的matplotlib
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))
也许http://jbdeaton.com/2011/speed-up-plot-rendering-in-pythonmatplotlib/可能有一定的帮助。将plot()调用添加rasterized = True。 –