好的,我最终将PIL图像上的行光栅化,然后将其转换为numpy数组:
from PIL import Imagefrom PIL import ImageDrawimport random as rndimport numpy as npimport matplotlib.pyplot as pltN = 60000s = (500, 500)im = Image.new('RGBA', s, (255,255,255,255))draw = ImageDraw.Draw(im)for i in range(N): x1 = rnd.random() * s[0] y1 = rnd.random() * s[1] x2 = rnd.random() * s[0] y2 = rnd.random() * s[1] alpha = rnd.random() color = (int(rnd.random() * 256), int(rnd.random() * 256), int(rnd.random() * 256), int(alpha * 256)) draw.line(((x1,y1),(x2,y2)), fill=color, width=1)plt.imshow(np.asarray(im),origin='lower')plt.show()这是迄今为止最快的解决方案,非常适合我的实时需求。需要注意的是,绘制线条时没有抗锯齿。



