1说明: 1。1VTK:我有介绍: 1。1。1《VTK:华为笔记本电脑深度deepinlinuxpython下安装和入门》 1。1。2确实,原始的vtk的python接口简直是太繁琐了,而且文档极其难看;与pyqt5和pyside2一样,功能强大,但是书写代码太繁琐,看着烦,不接受反驳。 1。2所以,诞生了:PyVista: 1。2。1PyVista是VTK的python高级API。 1。2。2官方称为:VTKforhumans:ahighlevelAPItotheVisualizationToolkit(VTK)。 1。2。3Pyvista是一套继承自VTK数据格式的python工具包,由于同VTK数据对象兼容。 2准备: 2。1官网:https:docs。pyvista。orgindex。htmlhttps:docs。pyvista。orgexamplesindex。htmlhttps:github。compyvistapyvista 2。2环境: 华为笔记本电脑、深度deepinlinux操作系统、python3。8和微软vscode编辑器。 2。3安装:pipinstallpyvista本机安装sudopip3。8installpyvista慢国内源安装,快sudopip3。8installihttps:mirrors。aliyun。compypisimplepyvista 3Helloworld: 3。1窗口基本设置: 3。1。1代码:导出模块importpyvistaaspv创建一个画板plotter,并实例化调出plotter绘图仪plotterpv。Plotter(titleFirst,windowsize(1000,1000))plotterpv。Plotter()setupcameraand展示窗口窗口标题名(不支持中文),窗口大小设置,在show和pv。Plotter中设置均可plotter。show(titleFirst,windowsize(1000,1000))plotter。show()关闭plotter。close() 3。1。2注意窗口的标题名,大小设置,注释里有。 3。2Helloworld 3。2。1代码:importpyvistaaspvplotterpv。Plotter()文本文字plotter。addtext(textHelloworld,positionupperleft,fontsize18,colorred,)窗口展示plotter。show(titleHelloworld,windowsize(1000,1000))plotter。close()附注:文本字的位置lowerleft,lowerright,upperleft,upperright,loweredge,upperedge,rightedge,leftedge 3。2。2图: 4图片显示: 4。1静态图片显示 4。1。1代码:importpyvistaaspvCreateaplotterobjectplotterpv。Plotter()背景图片,scale显示图片大小;格式jpg,png,jpegplotter。addbackgroundimage(homexgjDesktopVTKPyvistapic。jpeg,scale0。5)窗口展示plotter。show(titleshowpicture,windowsize(1000,1000))plotter。close() 4。1。2图: 4。2立体图: 4。2。1代码:importpyvistaaspvimagepv。read(homexgjDesktopVTKPyvistapic。jpeg)Trueimagecolorsimage。plot(rgbTrue,cposxy) 4。2。2效果图: 53Dplane飞机: 5。1方法一,代码:直接画飞机importpyvistaaspvfrompyvistaimportexamplesmesh为网格,这里是调出飞机模块函数,实例化meshexamples。loadairplane()screenshotairplane。png,保存图片png,在根目录下mesh。plot(screenshotairplane。png)mesh。plot() 5。2效果图: 5。3方法二,代码:先通过pv。Plotter()新建一个渲染窗口,然后通过addmesh增加mesh。importpyvistaaspvfrompyvistaimportexamplesmeshexamples。loadairplane()plotterpv。Plotter(windowsize〔1200,1200〕,titleplane,)instantiatetheplottercolor的颜色是渲染物的颜色,飞机的颜色plotter。addmesh(mesh,colortan)addameshtothescenecposplotter。show()showtherenderingwindowplotter。show()等同上面的 5。4效果图: 63D长方体: 6。1代码:importpyvistaaspvfrompyvistaimportexamplesmeshexamples。loadhexbeam()showedgesTrue,显示长方体的小网格mesh。plot(showedgesTrue) 6。2效果图: 73D地球: 7。1代码:importpyvistaaspvfrompyvistaimportexamplesmesh(examples。loadglobe())meshexamples。loadglobe()等同上面mesh。plot(showedgesTrue) 7。2效果图: 自己整理并分享出来 喜欢就点赞、收藏、转发、关注和评论。