Pyvista---(4)pyvista中常⽤的函数和应⽤1 pyvista中常⽤的函数和应⽤--1
1. 多个图,类似于matplotlib
p = pv.Plotter(shape=(3,3))
p.subplot(0,0)小米怎么关机
2. 指定颜⾊和平滑阴影
supertoroid.plot(color="tan", smooth_shading=True)
3. 创建点云
import pyvista as pv
import numpy as np
## ⽣成⼀组点云的坐标,然后构建点云的mesh
points = np.random.rand(30000,3)
point_cloud = pv.PolyData(points)
print np.allclo(points, point_cloud.points)#检测是否⼀致
微信电脑版安装
# 画点云
罗勒青酱
point_cloud.plot(eye_dome_lighting=True)
3.1 给点云赋值
## 给点云赋值,这⾥就把z轴坐标的值赋值给点云data = points[:,-1]
point_cloud["value"]= data
point_cloud.plot(render_points_as_spheres=True)
3.2 画向量,把向量的值存在点云中
因为mesh个⼀给点赋很多的值,通过字典的形式,只需要个数对的上,还有就是mesh中点的顺序要和值的存储顺序⼀样。
def compute_vectors(mesh):
origin =
vectors = mesh.points - origin小学运动会通讯稿
vectors = vectors / (vectors, axis=1)[:, None]
return vectors
vectors = compute_vectors(point_cloud)
寒门再难出贵子原文
point_cloud['vectors'] = vectors
arrows = point_cloud.glyph(orient='vectors', scale=Fal, factor=0.15,) #通过这个函数构建箭头
# Display the arrows童国贵
plotter = pv.Plotter()
plotter.add_mesh(point_cloud, color='maroon', point_size=10.,
render_points_as_spheres=True)
plotter.add_mesh(arrows, color='lightblue')雷公嘴
# plotter.add_point_labels([,], ['Center',],
# point_color='yellow', point_size=20)
plotter.show_grid()
plotter.show()
4. 画多⾯的图,并不是封闭
import pyvista as pv
# mesh points
vertices = np.array([[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, -1]])
# mesh faces,这个还不知道是什么意思,怎么定义?
faces = np.hstack([[4, 0, 1, 2, 3], # square
[3, 0, 1, 4], # triangle
[3, 1, 2, 4]]) # triangle
surf = pv.PolyData(vertices, faces)
# plot each face with a different color
# surf.plot(scalars=np.arange(3), cpos=[-1, 1, 0.5])
p = pv.Plotter() ## 建⼀个普通画板
# p = pv.BackgroundPlotter() ## 建⼀个交互式画板
p.camera_position = [-1, 1, 0.5]
p.add_mesh(surf)
p.show()
猪狗5. 画线条
docs.pyvista/examples/00-load/create-spline.html