栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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()

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/617275.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号