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. 创建点云
naked news korea
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 画向量,把向量的值存在点云中positioning
因为mesh个⼀给点赋很多的值,通过字典的形式,只需要个数对的上,还有就是mesh中点的顺序要和值的存储顺序⼀样。
def compute_vectors(mesh):
origin =
vectors = mesh.points - origin
vectors = vectors / (vectors, axis=1)[:, None]
return vectorscompetitions
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. 画多⾯的图,并不是封闭rainforest
import pyvista as pv
# mesh points
vertices = np.array([[0, 0, 0],
[1, 0, 0],
must
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, -1]])
royal holloway# 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