본문 바로가기

Programing Language/Python

[plot]LineCollection: edges(끈킨 선 여러개)를 빨리 그릴 때!?

반응형

원래 코드 (겁나 느림 주의)

# xs = [[fn1, tn1], [fn2, tn2]...]
# ys = [[fn1, tn1], [fn2, tn2]...]
plt.plot(xs.T, ys.T, lw = 1, c = 'r')
plt.show()

개선된 코드: 빠르다!!!

fn = np.array(list(zip(fx,fy)))
tn = np.array(list(zip(tx,ty)))
ptrs = np.array(list(zip(fn,tn)))

ln_coll = matplotlib.collections.LineCollection(ptrs, lw = lw*.05, colors='r')
fig, ax = plt.subplots()
ax.add_collection(ln_coll)
ax.autoscale()
ax.set_aspect('equal')
plt.show()

반응형