Matplotlib:绘制许多不同颜色的断开线段

Matplotlib:绘制许多不同颜色的断开线段,第1张

Matplotlib:绘制许多不同颜色的断开线段

好的,我最终将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()

这是迄今为止最快的解决方案,非常适合我的实时需求。需要注意的是,绘制线条时没有抗锯齿。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5623360.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存