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

使用matplotlib使用标签对点进行动画处理

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

使用matplotlib使用标签对点进行动画处理

您可以返回所有从更新功能更改的对象。因此,由于注释已更改,因此您还应该返回它的位置:

line.set_data(newData)annotation = plt.annotate('A0', xy=(newData[0][0],newData[1][0]))return line, annotation

您可以

matplotlib
在本教程中阅读有关动画的更多信息

您还应该指定

init
函数,以便
FuncAnimation
在第一次更新时重画时知道要从图中删除哪些元素。因此,完整的示例将是:

import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation# Create initial datadata = np.array([[1,2,3,4,5], [7,4,9,2,3]])# Create figure and axesfig = plt.figure()ax = plt.axes(xlim=(0, 20), ylim=(0, 20))# Create initial objectsline, = ax.plot([], [], 'r-')annotation = ax.annotate('A0', xy=(data[0][0], data[1][0]))annotation.set_animated(True)# Create the init function that returns the objects# that will change during the animation processdef init():    return line, annotation# Create the update function that returns all the# objects that have changeddef update(num):    newData = np.array([[1 + num, 2 + num / 2, 3, 4 - num / 4, 5 + num],  [7, 4, 9 + num / 3, 2, 3]])    line.set_data(newData)    # This is not working i 1.2.1    # annotation.set_position((newData[0][0], newData[1][0]))    annotation.xytext = (newData[0][0], newData[1][0])    return line, annotationanim = animation.FuncAnimation(fig, update, frames=25, init_func=init,         interval=200, blit=True)plt.show()


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

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

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