python - 使用 matplotlib animate 和 patch 为正方形和箭头设置动画
问题描述
我想使用矩形和 jupter notebook 中的箭头为机器人的位置和速度设置动画。矩形块表示机器人在网格上的位置,箭头表示机器人的速度矢量。网格是一个矩阵,显示为 imshow 热图,其中可能的障碍物具有高热量。
现在,我有一个如下所示的代码
from matplotlib import animation
from matplotlib import patches
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(9,9))
ax = fig.add_subplot(1,1,1)
rectangle = patches.Rectangle((0,0), robo_width, robot_length,)
arrow = patches.Arrow(0,0,0,5)
img = plt.imshow(grid[0], cmap='hot', interpolation='nearest', animated=True)
def update(frame):
rectangle.set_xy([x[frame], y[frame]])
img.set_array(grid[frame])
return img
animate = animation.FuncAnimation(fig, updatefig)
HTML(animate.to_jshtml())
有了这个,我可以在网格图像上绘制机器人正方形以显示机器人的位置。问题是,对于箭头补丁,我找不到类似于 set_xy() 的函数,也无法像矩形一样更新箭头。箭头有更新方法吗?还有另一种方法来绘制它吗?
解决方案
推荐阅读
- php - 为什么我无法使用 VichUploaderBundle 和 Symfony 5 在我的网页上显示图像?
- osgi - Karaf Bundle.getState() 与 bundle:list 中的 bundle 状态不完全匹配
- spring - Spring data jpa避免内存分页和n+1使用规范
- reactjs - 试图在特定页面上隐藏父组件
- sas - 打破 SAS 分类的联系
- python - 为什么我的第二个 Jinja for 循环没有运行?
- c++ - 如何防止我的函数的调用者在 C++ 中使用相同的按引用传递变量?
- css - 通过 uBlock Origin 中的 CSS 覆盖修复 div 的宽度
- java - 如何在 Spring-mvc 项目中配置静态文件(CSS/JS)?
- java - Android 电源菜单小部件快速访问钱包 PaymentCardManager