【发布时间】:2011-12-25 11:22:21
【问题描述】:
我有一些点(大约 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))
【问题讨论】:
-
也许jbdeaton.com/2011/speed-up-plot-rendering-in-pythonmatplotlib 可能会有所帮助。将 rasterized=True 添加到 plot() 调用中。
标签: python numpy matplotlib