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

仅根据绘图中的颜色更新的动画

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

仅根据绘图中的颜色更新的动画

LineCollection
为此最容易使用。这样,您可以将所有颜色设置为单个阵列,并且通常可以获得更好的绘图性能。

更好的性能主要是因为集合是在matplotlib中绘制许多相似对象的优化方法。在这种情况下,避免嵌套循环来设置颜色实际上是次要的。

考虑到这一点,请尝试以下方法:

import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib.collections import LineCollectionimport matplotlib.animation as animationlines=[]for i in range(10):    for j in range(10):        lines.append([(0, i), (1, j)])fig, ax = plt.subplots()colors = np.random.random(len(lines))col = LineCollection(lines, array=colors, cmap=plt.cm.gray, norm=plt.Normalize(0,1))ax.add_collection(col)ax.autoscale()def update(i):    colors = np.random.random(len(lines))    col.set_array(colors)    return col,# Setting this to a very short update interval to show rapid drawing.# 25ms would be more reasonable than 1ms.ani = animation.FuncAnimation(fig, update, interval=1, blit=True,         init_func=lambda: [col])# Some matplotlib versions explictly need an `init_func` to display properly...# Ideally we'd fully initialize the plot inside it. For simplicitly, we'll just# return the artist so that `FuncAnimation` knows what to draw.plt.show()



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

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

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