【100天精通Python】Day69:Python可视化_实战:导航定位中预测轨迹和实际轨迹的3D动画,示例+代码

目录

 1. 预测的3D轨迹和实际轨迹的动画图,同时动态更新

 2 真值轨迹设置为静态的,预测轨迹不断更新

 3 网格的三维坐标系有旋转运动,以此全方位展示预测轨迹和真值轨迹之间的空间关系


 1. 预测的3D轨迹和实际轨迹的动画图,同时动态更新

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation, PillowWriter# 假设您有两组连续平滑的姿势数据集,一组表示预测值,一组表示真值
# 每个数据点包含姿势信息 [x, y, z, roll, pitch, yaw]
# 这里使用一些示例数据,您需要替换为您的实际数据
num_poses = 200  # 增加轨迹点数
t = np.linspace(0, 20, num_poses)  # 时间点,使轨迹变得更长
# 生成示例数据来表示预测值轨迹
x_pred = np.sin(t)
y_pred = np.cos(t)
z_pred = np.linspace(0, 10, num_poses)
# 生成示例数据来表示真值轨迹
x_true = np.sin(t) + 0.5  # 真值轨迹稍微偏移
y_true = np.cos(t) + 0.5
z_true = np.linspace(0, 10, num_poses)# 创建一个 3D 图形
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')# 创建空的轨迹线,一个红色表示预测值,一个蓝色表示真值
line_pred, = ax.plot([], [], [], marker='o', linestyle='-', markersize=4, color='red', label='Predicted Trajectory')
line_true, = ax.plot([], [], [], marker='o', linestyle='-', markersize=4, color='green', label='True Trajectory')# 设置图形标题和轴标签
ax.set_title('Pose Trajectories (Predicted vs. True)')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')# 添加图例
ax.legend(loc='upper right')# 初始化函数,用于绘制空轨迹线
def init():line_pred.set_data([], [])line_pred.set_3d_properties([])line_true.set_data([], [])line_true.set_3d_properties([])return line_pred, line_true# 更新函数,用于更新轨迹线的数据
def update(frame):line_pred.set_data(x_pred[:frame], y_pred[:frame])line_pred.set_3d_properties(z_pred[:frame])line_true.set_data(x_true[:frame], y_true[:frame])line_true.set_3d_properties(z_true[:frame])# 扩大坐标范围,以包围轨迹ax.set_xlim(min(x_true) - 1, max(x_true) + 1)ax.set_ylim(min(y_true) - 1, max(y_true) + 1)ax.set_zlim(min(z_true) - 1, max(z_true) + 1)return line_pred, line_true# 创建动画对象
ani = FuncAnimation(fig, update, frames=num_poses, init_func=init, blit=True)# 创建一个文件名为animation.gif的视频文件,使用PillowWriter
ani.save('animation_gt.gif', writer=PillowWriter(fps=30))# 显示动画
plt.show()

2 真值轨迹设置为静态的,预测轨迹不断更新

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation, PillowWriter# 假设您有两组连续平滑的姿势数据集,一组表示预测值,一组表示真值
# 每个数据点包含姿势信息 [x, y, z, roll, pitch, yaw]
# 这里使用一些示例数据,您需要替换为您的实际数据
num_poses = 200  # 增加轨迹点数
t = np.linspace(0, 20, num_poses)  # 时间点,使轨迹变得更长
# 生成示例数据来表示预测值轨迹
x_pred = np.sin(t)
y_pred = np.cos(t)
z_pred = np.linspace(0, 10, num_poses)
# 生成示例数据来表示真值轨迹
x_true = np.sin(t) + np.random.uniform(-0.2, 0.3)  # 真值轨迹稍微偏移
y_true = np.sin(t) + np.random.uniform(-0.2, 0.3)  # 真值轨迹稍微偏移
z_true = np.linspace(0, 10, num_poses)# 创建一个 3D 图形
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')# 创建空的轨迹线,一个红色表示预测值,一个绿色表示真值
line_pred, = ax.plot([], [], [], marker='o', linestyle='-', markersize=4, color='red', label='Predicted Trajectory')
line_true, = ax.plot(x_true, y_true, z_true, marker='o', linestyle='-', markersize=4, color='green', label='True Trajectory')# 设置图形标题和轴标签
ax.set_title('Pose Trajectories (Predicted vs. True)')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')# 添加图例
ax.legend(loc='upper right')# 设置轨迹显示范围
ax.set_xlim(-2, 2)  # X轴范围
ax.set_ylim(-2, 2)  # Y轴范围
ax.set_zlim(0, 12)  # Z轴范围# 初始化函数,用于绘制空轨迹线
def init():line_pred.set_data([], [])line_pred.set_3d_properties([])return line_pred, line_true# 更新函数,用于更新预测轨迹的数据
def update(frame):line_pred.set_data(x_pred[:frame], y_pred[:frame])line_pred.set_3d_properties(z_pred[:frame])return line_pred, line_true# 创建动画对象
ani = FuncAnimation(fig, update, frames=num_poses, init_func=init, blit=True)# 创建一个文件名为animation.gif的视频文件,使用PillowWriter
ani.save('animation_1.gif', writer=PillowWriter(fps=30))# 显示动画
plt.show()

3 网格的三维坐标系有旋转运动,以此全方位展示预测轨迹和真值轨迹之间的空间关系

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation, PillowWriter# 假设您有两组连续平滑的姿势数据集,一组表示预测值,一组表示真值
# 每个数据点包含姿势信息 [x, y, z, roll, pitch, yaw]
# 这里使用一些示例数据,您需要替换为您的实际数据
num_poses = 200  # 增加轨迹点数
t = np.linspace(0, 20, num_poses)  # 时间点,使轨迹变得更长
# 生成示例数据来表示预测值轨迹
x_pred = np.sin(t)
y_pred = np.cos(t)
z_pred = np.linspace(0, 10, num_poses)
# 生成示例数据来表示真值轨迹
x_true = np.sin(t) + 0.5  # 真值轨迹稍微偏移
y_true = np.cos(t) + 0.5
z_true = np.linspace(0, 10, num_poses)# 创建一个 3D 图形
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')# 创建空的轨迹线,一个红色表示预测值,一个蓝色表示真值
line_pred, = ax.plot([], [], [], marker='o', linestyle='-', markersize=4, color='red', label='Predicted Trajectory')
line_true, = ax.plot(x_true, y_true, z_true, marker='o', linestyle='-', markersize=4, color='blue', label='True Trajectory')# 设置图形标题和轴标签
ax.set_title('Pose Trajectories (Predicted vs. True)')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')# 添加图例
ax.legend(loc='upper right')# 设置轨迹显示范围
ax.set_xlim(-2, 2)  # X轴范围
ax.set_ylim(-2, 2)  # Y轴范围
ax.set_zlim(0, 12)  # Z轴范围# 初始化函数,用于绘制空轨迹线
def init():line_pred.set_data([], [])line_pred.set_3d_properties([])return line_pred, line_true# 更新函数,用于更新预测轨迹的数据和整体的旋转运动
def update(frame):line_pred.set_data(x_pred[:frame], y_pred[:frame])line_pred.set_3d_properties(z_pred[:frame])# 添加整体的旋转运动ax.view_init(elev=20, azim=frame)  # 调整视角,azim控制旋转return line_pred, line_true# 创建动画对象
ani = FuncAnimation(fig, update, frames=num_poses, init_func=init, blit=True)# 创建一个文件名为animation.gif的视频文件,使用PillowWriter
ani.save('animation.gif', writer=PillowWriter(fps=30))# 显示动画
plt.show()

更新函数中使用了ax.view_init来控制整体的旋转运动,elev参数用于调整仰角,azim参数用于控制旋转。您可以根据需要调整elevazim的值来实现所需的旋转效果。

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/86195.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vivo面试-Java

一、JAVA八股 1、Java实现线程的三种方式 (1) 继承 Thread 类: 创建一个新类,该类继承自Thread类,并重写run方法。然后创建该类的实例,并调用它的start方法来启动线程。 public class MyThread extends Thread {public void r…

【自然语言处理】关系抽取 —— SOLS 讲解

SOLS 论文信息 标题:Speaker-Oriented Latent Structures for Dialogue-Based Relation Extraction 作者:Guoshun Nan, Guoqing Luo, Sicong Leng, Yao Xiao, Wei Lu 发布时间与更新时间:2021.09.11 主题:自然语言处理、关系抽取、对话场景、跨语句、DialogRE、GCN arXiv:…

【owt】 Intel® Media SDK for Windows: MSDK2021R1

https://www.intel.com/content/www/us/en/developer/articles/tool/media-sdk.html官方网不提供下载了: 2021地址 直接下载: MSDK2021R1.exe老版本 Intel Media SDK(Windows版本) 大神的介绍:owt-client-native 需要 https://github.com/open-webrtc-toolkit/owt-client…

罗德里格斯公式

1.点乘 A ⃗ ⋅ B ⃗ ∣ A ⃗ ∣ ∣ B ⃗ ∣ c o s ⟨ A ⃗ , B ⃗ ⟩ \vec{A} \cdot \vec{B} \left | \vec{A} \right | \left | \vec{B} \right | cos\left \langle \vec{A}, \vec{B} \right \rangle A ⋅B ​A ​ ​B ​cos⟨A ,B ⟩ 对应几何意义:向量 A ⃗…

面向使用者的git与gerrit相关笔记

git与gerrit相关笔记 前言一、gerrit是什么?二、一些配置1.先配置全局email 和name2.gerrit配置ssh key3.可能遇到的问题 三、提交代码和合并冲突常用Git命令三件套严格的要求 总结 前言 本文是介绍什么是gerrit和工作中git与gerrit相关的命令来避免一些提交代码的…

05_CSS进阶技巧

1 CSS 规范 遵循以下顺序 布局定位属性:display/position/float/clear/visibility/overflow(建议 display 第一个写)自身属性:width/height/margin/padding/border/background文本属性:color/font/text-decoraction/…

EMQX Enterprise 5.2 发布:Flow 设计器,Amazon Kinesis,Azure Event Hubs

EMQX Enterprise 5.2.0 版本现已正式发布! 新版本带来了一系列重磅更新,最令人瞩目的是可拖拽的可视化 Flow 设计器,它可以帮助企业快速创建、测试和部署数据集成。同时,我们新增了对 Amazon Kinesis 和 Azure Event Hubs 的支持…

React 如何导出excel

在现代的Web开发中,数据导出是一个非常常见的需求。而在React应用中,我们经常需要将数据导出为Excel文件,以便用户可以轻松地在本地计算机上查看和编辑。本文将介绍如何在React应用中实现导出Excel文件的功能。 章节一:安装依赖 …

VMware安装CentOS Stream 8以及JDK和Docker

一、下载镜像源 地址:https://developer.aliyun.com/mirror/?spma2c6h.25603864.0.0.285b32d48O2G8Y 二、安装配置 配置项 一共有以下这些,其中软件、软件选择 、安装目的地、网络主机名需要讲一下,其他都简单,自行设置即可。 …

电脑出现丢失msvcp71.dll的解决方法_常见msvcp71.dll解决方法

当电脑提示“找不到 msvcp71.dll”时,意味着您的系统缺少这个重要的动态链接库文件。msvcp71.dll 是 Visual Studio 2010 运行时所需的一个组件,因此如果您安装了 Visual Studio 2010 或更高版本,那么您很可能会遇到这个问题。以下是解决这个…

uni-app实现web-view图片长按下载

<template><view><web-view :webview-styles"webviewStyles" :src"webUrl"></web-view></view> </template> uniapp的web-view中图片无法长按保存&#xff0c;IOS下是正常的&#xff0c;但是Android下长按无反应 解…

Spring Cloud Alibaba Gateway 全链路跟踪TraceId日志

前言 凡是文中需要注册到nacos的都需要这个jar包 <dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency>凡是使用config jar包的都需要写bootstrap.prop…

React实战过程的知识了解

做项目用到react和antd&#xff0c;没办法循序渐进的学习&#xff0c;只能把一些点记录在这里&#xff0c;希望大家指正。 1.杂七杂八 正文 //actionRef&#xff0c;操作表单的预设方法&#xff0c;包括&#xff1a;刷新、重置所有项并刷新、重置到默认项、加载更多、清空选…

ipad触控笔有必要买原装吗?ipad2023手写笔推荐

目前&#xff0c;在无纸教学、无纸办公的大背景下&#xff0c;电容笔得到了广泛的关注。只是&#xff0c;对于这两支电容笔的不同之处&#xff0c;不少人并不是很清楚。其实这两种电容笔都很好区分&#xff0c;第一种是主动电容笔&#xff0c;也就是我们常用的电容式屏幕&#…

[JAVAee]Spring MVC

目录 Spring MVC框架 MVC Spring MVC的功能 用户与程序的连接 RequestMapping 指定为Get请求 指定为Post请求 获取参数 单个参数 表单传递多个参数 传递对象 后端参数重命名(后端参数映射) 设置参数必传/非必传 获取JSON对象 获取URL中的参数 上传文件 获取…

十六、MySql的MVCC机制CONNECT(收官!)

文章目录 一、数据库并发的场景有三种&#xff1a;二、读-写&#xff08;一&#xff09;3个记录隐藏列字段&#xff08;二&#xff09;undo 日志&#xff08;三&#xff09;模拟 MVCC&#xff08;四&#xff09;一些思考&#xff08;五&#xff09;Read View 一、数据库并发的场…

【深度学习】Pytorch 系列教程(十二):PyTorch数据结构:4、数据集(Dataset)

目录 一、前言 二、实验环境 三、PyTorch数据结构 0、分类 1、张量&#xff08;Tensor&#xff09; 2、张量操作&#xff08;Tensor Operations&#xff09; 3、变量&#xff08;Variable&#xff09; 4、数据集&#xff08;Dataset&#xff09; 随机洗牌 一、前言 Ch…

FPGA——WS2812B彩灯点亮

文章目录 前言一、WS2812B手册分析原理1.1 主要特点1.2 器件图1.3 接口1.4 输入码型1.5 归零码&#xff08;RZ&#xff09;和非归零码(NRZ)&#xff08;拓展&#xff09;1.6 级联输出1.7 输入数据格式 二、FPGA点亮彩灯2.1 代码 三、总结 前言 本篇博客是记录WS2812手册的学习…

web二级操作题

js和css的引入 在 HTML 中&#xff0c;你可以使用 <script> 和 <link> 标签来引入外部的 JavaScript 文件和 CSS 文件。 引入外部的 JavaScript 文件&#xff1a; <script src"path/to/script.js"></script>src 属性指定了 JavaScript 文…

关于PyInstaller打包exe程序的参数用法大全

PyInstaller可以将Python程序打包成一个exe程序来独立运行&#xff0c;用户使用时只需要执行这个exe文件即可&#xff0c;不需要在机器上再安装Python及其他包就可运行了。另外&#xff0c;PyInstaller相较于其他打包程序&#xff0c;比如py2exe&#xff0c;大多时候使用起来更…