在pyvista 中,显示带透明度的点云信息

python 复制代码
import pyvista as pv
import numpy as np

# Number of points
num_points = 1000

# Generate random points on the surface of a sphere
phi = np.random.uniform(0, 2 * np.pi, num_points)
#theta = np.acos(1 - 2 * np.random.rand(num_points))
theta = np.arccos(1 - 2 * np.random.rand(num_points))
x = 10 * np.sin(theta) * np.cos(phi)
y = 10 * np.sin(theta) * np.sin(phi)
z = 10 * np.cos(theta)
points = np.column_stack((x, y, z))
colors = np.random.rand(num_points,4)
# Create a PyVista PolyData object
cloud = pv.PolyData(points)

# Assign random brightness to each point
#cloud.point_data["brightness"] = np.random.rand(num_points)
cloud.point_data["colors"]=colors
# Assign transparency based on z value
# Normalize z values to range [0, 1] for opacity
z_normalized = (z - z.min()) / (z.max() - z.min())
opacity = 1 - z_normalized  # Increase opacity with increasing z

# Plot the point cloud
plotter = pv.Plotter()
#plotter.add_points(cloud,opacity=opacity)
plotter.add_points(cloud,rgb=True)
plotter.set_background('black') 
plotter.show()

程序设计了一个含有一千个点的球面,每个点的颜色和透明度随机。

还有一种方式,就是用"brightness"和opacity=opacity来对幅值和透明度来显示点云。

python 复制代码
points=np.column_stack((x, y, z))
alphas=np.random.rand(num_points)
point_cloud = pv.PolyData(points)    
plotter = pv.Plotter()
point_cloud.point_data["brightness"]=alphas
point_cloud['opacity']= alphas
plotter.add_points(point_cloud,scalars='brightness',opacity=opacity,point_size=5)
plotter.add_axes()
plotter.show()
相关推荐
Johny_Zhao11 小时前
CentOS Stream 8 高可用 Kuboard 部署方案
linux·网络·python·网络安全·docker·信息安全·kubernetes·云计算·shell·yum源·系统运维·kuboard
站大爷IP12 小时前
精通einsum():多维数组操作的瑞士军刀
python
站大爷IP12 小时前
Python与MongoDB的亲密接触:从入门到实战的代码指南
python
Roc-xb13 小时前
/etc/profile.d/conda.sh: No such file or directory : numeric argument required
python·ubuntu·conda
世由心生14 小时前
[从0到1]环境准备--anaconda与pycharm的安装
ide·python·pycharm
猛犸MAMMOTH15 小时前
Python打卡第54天
pytorch·python·深度学习
梓羽玩Python15 小时前
12K+ Star的离线语音神器!50MB模型秒杀云端API,隐私零成本,20+语种支持!
人工智能·python·github
成都犀牛15 小时前
LangGraph 深度学习笔记:构建真实世界的智能代理
人工智能·pytorch·笔记·python·深度学习
終不似少年遊*15 小时前
【数据可视化】Pyecharts-家乡地图
python·信息可视化·数据挖掘·数据分析·数据可视化·pyecharts
仟濹16 小时前
「Matplotlib 入门指南」 Python 数据可视化分析【数据分析全栈攻略:爬虫+处理+可视化+报告】
python·信息可视化·数据分析·matplotlib