当前位置: 首页 > news >正文

python给三维点上色,并添加颜色柱

python的matplotlib库给三维点上色,并添加颜色柱

import numpy as np
from pathlib import Path
import matplotlib.cm as cm
import matplotlib.pyplot as plt# 可视化3d点迹
def Show3D_complete(points3D_result, color_list, save_path):# 指定起止点start_point = points3D_result[0]end_point = points3D_result[-1]# 截取中间点points3D_result_T = points3D_result[1:-1].Tcolor_list = color_list[1:-1]ax = plt.subplot(projection = '3d')ax.set_title('3d_points_show')ax.scatter(start_point[0], start_point[1], start_point[2], s=60, c = 'aqua')                            # 绘制起点ax.scatter(end_point[0], end_point[1], end_point[2], s=60, c = 'red')                                   # 绘制终点sc = ax.scatter(points3D_result_T[0], points3D_result_T[1], points3D_result_T[2], s=30, c=color_list, cmap='Greens')   # 绘制中间曲线 jet YlGn winter PiYG Blues# ax.set_xlim3d(xmin=-20, xmax=10)# ax.set_ylim3d(ymin=-55,    ymax=25)# ax.set_zlim3d(zmin=-10, zmax=5)ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')ax.view_init(40, -50, 0)cbar = plt.colorbar(sc, fraction=0.028, pad=0.15)cbar.set_label('Speed', rotation=0, fontsize=8)plt.savefig(str(save_path), dpi=420)plt.show()plt.close()def get_color(rate):if isinstance(rate, np.ndarray):colormap = cm.get_cmap('jet')color = colormap(rate)[:, 0:3]else:color = cm.get_cmap('jet')(rate)return colorif __name__ == '__main__':root_path = Path("data/20240525")for dir in root_path.iterdir():print(f"dir: {dir}")if dir.is_file():continuefor trajectory_txt in dir.glob('*.txt'):filter_txt_list = trajectory_txt.open('r').readlines()time_list = []speed_list = []point_list = []for idx, log in enumerate(filter_txt_list):data_fields = log.split(',')if len(data_fields) <= 2:print(f"data_fields <= 2: {data_fields}")continuex, y, z = float(data_fields[1]), float(data_fields[2]), float(data_fields[3])speed_list.append(float(data_fields[4]))point_list.append([x, y, z])print(f"len(point_list): {len(point_list)}")color_rate = np.array(speed_list) / (max(speed_list) - min(speed_list))Show3D_complete(np.array(point_list), color_rate)break
http://www.lryc.cn/news/355236.html

相关文章:

  • Ubuntu22.04之解决:忘记登录密码(二百三十二)
  • stream-并行流
  • 插件“猫抓”使用方法 - 浏览器下载m3u8视频 - 合并 - 视频检测下载 - 网课下载神器
  • 【quarkus系列】构建可执行文件native image
  • linux(ubuntu)常用的代理设置
  • 红队攻防渗透技术实战流程:红队目标上线之Webshell免杀对抗
  • Habicht定理中有关子结式命题3.4.6的证明
  • 【Unity AR开发插件】如何快速地开发可热更的AR应用
  • Divisibility Part1(整除理论1)
  • 代码随想录算法训练营第三十七天 | 860.柠檬水找零、406.根据身高重建队列、452.用最少数量的箭引爆气球
  • GolangFoundation
  • 如果任务过多,队列积压怎么处理?
  • FTP协议——BFTPD基本操作(Ubuntu+Win)
  • 为什么需要分布式 ID?
  • MIT6.828 Lab2-3 Sysinfo
  • 形态学操作:腐蚀、膨胀、开闭运算、顶帽底帽变换、形态学梯度区别与联系
  • StringBufferInputStream类,你学会了吗?
  • 06_Tomcat
  • 系统安全扫描扫出了:可能存在 CSRF 攻击怎么办
  • Android ART 虚拟机简析
  • Android低代码开发 - MenuPanel的源码剖析和基本使用
  • Leetcode刷题笔记3
  • 初识C语言——第二十九天
  • LeetCode27.移除元素
  • DiffMap:首个利用LDM来增强高精地图构建的网络
  • ComfyUI简单介绍
  • 【内存泄漏Bug】animation未释放
  • 《异常检测——从经典算法到深度学习》28 UNRAVEL ANOMALIES:基于周期与趋势分解的时间序列异常检测端到端方法
  • Python正则模块re方法介绍
  • pdf使用pdfbox切割pdf文件MultipartFile