文中根据对pyvista这一相对性“小众”的python三维可视化专用工具的探索,汇总了安裝与基本上的应用实例,包含单控制模块、多控制模块、静态数据图、动态性绘图工具、gif和mp4视频的导出来等。整体而言pyvista是一款3D渲染实际效果非常好的可视化软件,可是特性相对而言沒有那麼丰厚,针对经营规模并不大的管理体系或是一个十分功能强大的专用工具,强烈推荐应用。

技术性情况

三维可视化是一项在工业生产行业中十分关键的技术性,而Python中最受欢迎的数据分析工具matplotlib和plotly,更为趋向于在数据信息行业的数据可视化,用以呈现数据信息的結果。相近的也有百度搜索的pyechart也相对性美观大方,可是这种终究全是在数据信息方面的数据可视化,针对工业生产行业,例如一个地貌,一个三维的期内这些,用这种专用工具来做可视化效果十分的欠佳,因而我找到了pyvista这一专用工具,简易探索了一下给大伙儿做一个举荐。

安裝pyvista

由于pyvista以及依靠全是一些python库,这就促使大家可以用pip立即简易的安裝,这儿放好多个很有可能采用的依靠的安裝步骤:

(base) dechin@ubuntu2004:~/projects$ python3 -m pip install vtk==9.0.20210612.dev0
Collecting vtk==9.0.20210612.dev0
  Downloading vtk-9.0.20210612.dev0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (80.9 MB)
     |████████████████████████████████| 80.9 MB 3.7 MB/s 
Requirement already satisfied: wslink>=0.1.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk==9.0.20210612.dev0) (0.2.0)
Requirement already satisfied: Twisted>=17.5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk==9.0.20210612.dev0) (21.2.0)
Requirement already satisfied: matplotlib>=2.0.0 in /home/dechin/.local/lib/python3.8/site-packages (from vtk==9.0.20210612.dev0) (3.3.4)
Requirement already satisfied: autobahn>=17.7.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk==9.0.20210612.dev0) (21.3.1)
Requirement already satisfied: cryptography>=3.4.6 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk==9.0.20210612.dev0) (3.4.7)
Requirement already satisfied: txaio>=21.2.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk==9.0.20210612.dev0) (21.2.1)
Requirement already satisfied: hyperlink>=21.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk==9.0.20210612.dev0) (21.0.0)
Requirement already satisfied: cffi>=1.12 in /home/dechin/anaconda3/lib/python3.8/site-packages (from cryptography>=3.4.6->autobahn>=17.7.1->vtk==9.0.20210612.dev0) (1.14.5)
Requirement already satisfied: pycparser in /home/dechin/anaconda3/lib/python3.8/site-packages (from cffi>=1.12->cryptography>=3.4.6->autobahn>=17.7.1->vtk==9.0.20210612.dev0) (2.20)
Requirement already satisfied: idna>=2.5 in /home/dechin/.local/lib/python3.8/site-packages (from hyperlink>=21.0.0->autobahn>=17.7.1->vtk==9.0.20210612.dev0) (2.10)
Requirement already satisfied: python-dateutil>=2.1 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (2.8.1)
Requirement already satisfied: pillow>=6.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (8.2.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (1.3.1)
Requirement already satisfied: numpy>=1.15 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (1.20.2)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (0.10.0)
Requirement already satisfied: six in /home/dechin/.local/lib/python3.8/site-packages (from cycler>=0.10->matplotlib>=2.0.0->vtk==9.0.20210612.dev0) (1.16.0)
Requirement already satisfied: zope.interface>=4.4.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk==9.0.20210612.dev0) (5.4.0)
Requirement already satisfied: attrs>=19.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk==9.0.20210612.dev0) (21.2.0)
Requirement already satisfied: constantly>=15.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk==9.0.20210612.dev0) (15.1.0)
Requirement already satisfied: Automat>=0.8.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk==9.0.20210612.dev0) (20.2.0)
Requirement already satisfied: incremental>=16.10.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk==9.0.20210612.dev0) (21.3.0)
Requirement already satisfied: setuptools in /home/dechin/anaconda3/lib/python3.8/site-packages (from zope.interface>=4.4.2->Twisted>=17.5.0->vtk==9.0.20210612.dev0) (52.0.0.post20210125)
Installing collected packages: vtk
  Attempting uninstall: vtk
    Found existing installation: vtk 9.0.2
    Uninstalling vtk-9.0.2:
      Successfully uninstalled vtk-9.0.2
Successfully installed vtk-9.0.20210612.dev0

安裝pyvista的情况下最好是再加上一个中国的镜像源,不然有可能发生网络问题,别的的包不用加镜像源:

(base) dechin@ubuntu2004:~/projects$ python3 -m pip install pyvista --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple
Looking in indexes: https://repo.huaweicloud.com/repository/pypi/simple
Collecting pyvista
  Downloading https://repo.huaweicloud.com/repository/pypi/packages/ec/00/292dc2f14247d74098806dcb9e1bb0c416b936c145ca9ab4e940b6f90d4f/pyvista-0.31.3-py3-none-any.whl (1.3 MB)
     |████████████████████████████████| 1.3 MB 2.7 MB/s 
Requirement already satisfied: imageio in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista) (2.9.0)
Requirement already satisfied: numpy in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista) (1.20.2)
Requirement already satisfied: pillow in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista) (8.2.0)
Collecting scooby>=0.5.1
  Downloading https://repo.huaweicloud.com/repository/pypi/packages/1b/99/db6d34bdc3f060d631f524c2f0fc4b1919cd3bf734c905fc1b25eb847ac2/scooby-0.5.7-py3-none-any.whl (13 kB)
Collecting transforms3d==0.3.1
  Downloading https://repo.huaweicloud.com/repository/pypi/packages/b5/f7/e85809168a548a854d7c1331560c27b4f5381698d29c12e57759192b2bc1/transforms3d-0.3.1.tar.gz (62 kB)
     |████████████████████████████████| 62 kB 2.2 MB/s 
Requirement already satisfied: vtk in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista) (9.0.20210612.dev0)
Requirement already satisfied: appdirs in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista) (1.4.4)
Collecting meshio<5.0,>=4.0.3
  Downloading https://repo.huaweicloud.com/repository/pypi/packages/bb/36/02702cfc5fdf19e6477ea2a78cac4a774a8da4c2cf9557f3ddfb33c74192/meshio-4.4.6-py3-none-any.whl (158 kB)
     |████████████████████████████████| 158 kB 2.7 MB/s 
Requirement already satisfied: autobahn>=17.7.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk->pyvista) (21.3.1)
Requirement already satisfied: wslink>=0.1.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk->pyvista) (0.2.0)
Requirement already satisfied: matplotlib>=2.0.0 in /home/dechin/.local/lib/python3.8/site-packages (from vtk->pyvista) (3.3.4)
Requirement already satisfied: Twisted>=17.5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk->pyvista) (21.2.0)
Requirement already satisfied: txaio>=21.2.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk->pyvista) (21.2.1)
Requirement already satisfied: cryptography>=3.4.6 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk->pyvista) (3.4.7)
Requirement already satisfied: hyperlink>=21.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk->pyvista) (21.0.0)
Requirement already satisfied: cffi>=1.12 in /home/dechin/anaconda3/lib/python3.8/site-packages (from cryptography>=3.4.6->autobahn>=17.7.1->vtk->pyvista) (1.14.5)
Requirement already satisfied: pycparser in /home/dechin/anaconda3/lib/python3.8/site-packages (from cffi>=1.12->cryptography>=3.4.6->autobahn>=17.7.1->vtk->pyvista) (2.20)
Requirement already satisfied: idna>=2.5 in /home/dechin/.local/lib/python3.8/site-packages (from hyperlink>=21.0.0->autobahn>=17.7.1->vtk->pyvista) (2.10)
Requirement already satisfied: python-dateutil>=2.1 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista) (2.8.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista) (1.3.1)
Requirement already satisfied: six in /home/dechin/.local/lib/python3.8/site-packages (from cycler>=0.10->matplotlib>=2.0.0->vtk->pyvista) (1.16.0)
Requirement already satisfied: zope.interface>=4.4.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista) (5.4.0)
Requirement already satisfied: attrs>=19.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista) (21.2.0)
Requirement already satisfied: constantly>=15.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista) (15.1.0)
Requirement already satisfied: Automat>=0.8.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista) (20.2.0)
Requirement already satisfied: incremental>=16.10.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista) (21.3.0)
Requirement already satisfied: setuptools in /home/dechin/anaconda3/lib/python3.8/site-packages (from zope.interface>=4.4.2->Twisted>=17.5.0->vtk->pyvista) (52.0.0.post20210125)
Building wheels for collected packages: transforms3d
  Building wheel for transforms3d (setup.py) ... done
  Created wheel for transforms3d: filename=transforms3d-0.3.1-py3-none-any.whl size=59373 sha256=56293f06c7932f3c12d57476773220d4219d8a978257f84bf56f4a8be8cccb2b
  Stored in directory: /home/dechin/.cache/pip/wheels/45/80/2d/22eb03277c315a020a6fdb617cc1232ef4ddc04dc2f00b8a22
Successfully built transforms3d
Installing collected packages: transforms3d, scooby, meshio, pyvista
Successfully installed meshio-4.4.6 pyvista-0.31.3 scooby-0.5.7 transforms3d-0.3.1

此外也有这一三维可互动控制面板制作的软件:

(base) dechin@ubuntu2004:~/projects$ python3 -m pip install ipygany
Collecting ipygany
  Using cached ipygany-0.5.0-py2.py3-none-any.whl (2.9 MB)
Requirement already satisfied: numpy in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipygany) (1.20.2)
Requirement already satisfied: traittypes in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipygany) (0.2.1)
Requirement already satisfied: ipywidgets>=7.6.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipygany) (7.6.3)
Requirement already satisfied: ipython>=4.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipywidgets>=7.6.0->ipygany) (7.22.0)
Requirement already satisfied: ipykernel>=4.5.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipywidgets>=7.6.0->ipygany) (5.3.4)
Requirement already satisfied: widgetsnbextension~=3.5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipywidgets>=7.6.0->ipygany) (3.5.1)
Requirement already satisfied: jupyterlab-widgets>=1.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipywidgets>=7.6.0->ipygany) (1.0.0)
Requirement already satisfied: traitlets>=4.3.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipywidgets>=7.6.0->ipygany) (5.0.5)
Requirement already satisfied: nbformat>=4.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipywidgets>=7.6.0->ipygany) (5.1.3)
Requirement already satisfied: jupyter-client in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipykernel>=4.5.1->ipywidgets>=7.6.0->ipygany) (6.1.12)
Requirement already satisfied: tornado>=4.2 in /home/dechin/.local/lib/python3.8/site-packages (from ipykernel>=4.5.1->ipywidgets>=7.6.0->ipygany) (6.1)
Requirement already satisfied: backcall in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (0.2.0)
Requirement already satisfied: pygments in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (2.9.0)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (3.0.17)
Requirement already satisfied: decorator in /home/dechin/.local/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (4.4.2)
Requirement already satisfied: pexpect>4.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (4.8.0)
Requirement already satisfied: jedi>=0.16 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (0.17.2)
Requirement already satisfied: setuptools>=18.5 in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (52.0.0.post20210125)
Requirement already satisfied: pickleshare in /home/dechin/anaconda3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (0.7.5)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from jedi>=0.16->ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (0.7.0)
Requirement already satisfied: jupyter-core in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbformat>=4.2.0->ipywidgets>=7.6.0->ipygany) (4.7.1)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbformat>=4.2.0->ipywidgets>=7.6.0->ipygany) (3.2.0)
Requirement already satisfied: ipython-genutils in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbformat>=4.2.0->ipywidgets>=7.6.0->ipygany) (0.2.0)
Requirement already satisfied: six>=1.11.0 in /home/dechin/.local/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets>=7.6.0->ipygany) (1.16.0)
Requirement already satisfied: pyrsistent>=0.14.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets>=7.6.0->ipygany) (0.17.3)
Requirement already satisfied: attrs>=17.4.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets>=7.6.0->ipygany) (21.2.0)
Requirement already satisfied: ptyprocess>=0.5 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pexpect>4.3->ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (0.7.0)
Requirement already satisfied: wcwidth in /home/dechin/anaconda3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=4.0.0->ipywidgets>=7.6.0->ipygany) (0.2.5)
Requirement already satisfied: notebook>=4.4.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (6.4.0)
Requirement already satisfied: pyzmq>=17 in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (20.0.0)
Requirement already satisfied: Send2Trash>=1.5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (1.5.0)
Requirement already satisfied: terminado>=0.8.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.9.4)
Requirement already satisfied: argon2-cffi in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (20.1.0)
Requirement already satisfied: nbconvert in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (6.1.0)
Requirement already satisfied: jinja2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (3.0.1)
Requirement already satisfied: prometheus-client in /home/dechin/anaconda3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.11.0)
Requirement already satisfied: python-dateutil>=2.1 in /home/dechin/.local/lib/python3.8/site-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets>=7.6.0->ipygany) (2.8.1)
Requirement already satisfied: cffi>=1.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (1.14.5)
Requirement already satisfied: pycparser in /home/dechin/anaconda3/lib/python3.8/site-packages (from cffi>=1.0.0->argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (2.20)
Requirement already satisfied: MarkupSafe>=2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from jinja2->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (2.0.1)
Requirement already satisfied: entrypoints>=0.2.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.3)
Requirement already satisfied: pandocfilters>=1.4.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (1.4.3)
Requirement already satisfied: testpath in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.5.0)
Requirement already satisfied: nbclient<0.6.0,>=0.5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.5.3)
Requirement already satisfied: jupyterlab-pygments in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.1.2)
Requirement already satisfied: mistune<2,>=0.8.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.8.4)
Requirement already satisfied: defusedxml in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.7.1)
Requirement already satisfied: bleach in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (3.3.0)
Requirement already satisfied: nest-asyncio in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbclient<0.6.0,>=0.5.0->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (1.5.1)
Requirement already satisfied: async-generator in /home/dechin/anaconda3/lib/python3.8/site-packages (from nbclient<0.6.0,>=0.5.0->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (1.10)
Requirement already satisfied: webencodings in /home/dechin/anaconda3/lib/python3.8/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (0.5.1)
Requirement already satisfied: packaging in /home/dechin/anaconda3/lib/python3.8/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (20.9)
Requirement already satisfied: pyparsing>=2.0.2 in /home/dechin/.local/lib/python3.8/site-packages (from packaging->bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets>=7.6.0->ipygany) (2.4.7)
Installing collected packages: ipygany
Successfully installed ipygany-0.5.0

及其一个根据pyqt的一个弹出式制图软件:

(base) dechin@ubuntu2004:~/projects$ python3 -m pip install pyvistaqt
Collecting pyvistaqt
  Downloading pyvistaqt-0.5.0-py3-none-any.whl (162 kB)
     |████████████████████████████████| 162 kB 1.1 MB/s 
Requirement already satisfied: QtPy>=1.9.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvistaqt) (1.9.0)
Requirement already satisfied: pyvista>=0.25.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvistaqt) (0.31.3)
Requirement already satisfied: pillow in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (8.2.0)
Requirement already satisfied: meshio<5.0,>=4.0.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (4.4.6)
Requirement already satisfied: scooby>=0.5.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (0.5.7)
Requirement already satisfied: imageio in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (2.9.0)
Requirement already satisfied: appdirs in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (1.4.4)
Requirement already satisfied: numpy in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (1.20.2)
Requirement already satisfied: vtk in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (9.0.20210612.dev0)
Requirement already satisfied: transforms3d==0.3.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from pyvista>=0.25.0->pyvistaqt) (0.3.1)
Requirement already satisfied: autobahn>=17.7.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk->pyvista>=0.25.0->pyvistaqt) (21.3.1)
Requirement already satisfied: Twisted>=17.5.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk->pyvista>=0.25.0->pyvistaqt) (21.2.0)
Requirement already satisfied: matplotlib>=2.0.0 in /home/dechin/.local/lib/python3.8/site-packages (from vtk->pyvista>=0.25.0->pyvistaqt) (3.3.4)
Requirement already satisfied: wslink>=0.1.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from vtk->pyvista>=0.25.0->pyvistaqt) (0.2.0)
Requirement already satisfied: hyperlink>=21.0.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk->pyvista>=0.25.0->pyvistaqt) (21.0.0)
Requirement already satisfied: cryptography>=3.4.6 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk->pyvista>=0.25.0->pyvistaqt) (3.4.7)
Requirement already satisfied: txaio>=21.2.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from autobahn>=17.7.1->vtk->pyvista>=0.25.0->pyvistaqt) (21.2.1)
Requirement already satisfied: cffi>=1.12 in /home/dechin/anaconda3/lib/python3.8/site-packages (from cryptography>=3.4.6->autobahn>=17.7.1->vtk->pyvista>=0.25.0->pyvistaqt) (1.14.5)
Requirement already satisfied: pycparser in /home/dechin/anaconda3/lib/python3.8/site-packages (from cffi>=1.12->cryptography>=3.4.6->autobahn>=17.7.1->vtk->pyvista>=0.25.0->pyvistaqt) (2.20)
Requirement already satisfied: idna>=2.5 in /home/dechin/.local/lib/python3.8/site-packages (from hyperlink>=21.0.0->autobahn>=17.7.1->vtk->pyvista>=0.25.0->pyvistaqt) (2.10)
Requirement already satisfied: python-dateutil>=2.1 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista>=0.25.0->pyvistaqt) (2.8.1)
Requirement already satisfied: cycler>=0.10 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista>=0.25.0->pyvistaqt) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista>=0.25.0->pyvistaqt) (1.3.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /home/dechin/.local/lib/python3.8/site-packages (from matplotlib>=2.0.0->vtk->pyvista>=0.25.0->pyvistaqt) (2.4.7)
Requirement already satisfied: six in /home/dechin/.local/lib/python3.8/site-packages (from cycler>=0.10->matplotlib>=2.0.0->vtk->pyvista>=0.25.0->pyvistaqt) (1.16.0)
Requirement already satisfied: Automat>=0.8.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista>=0.25.0->pyvistaqt) (20.2.0)
Requirement already satisfied: attrs>=19.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista>=0.25.0->pyvistaqt) (21.2.0)
Requirement already satisfied: constantly>=15.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista>=0.25.0->pyvistaqt) (15.1.0)
Requirement already satisfied: zope.interface>=4.4.2 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista>=0.25.0->pyvistaqt) (5.4.0)
Requirement already satisfied: incremental>=16.10.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from Twisted>=17.5.0->vtk->pyvista>=0.25.0->pyvistaqt) (21.3.0)
Requirement already satisfied: setuptools in /home/dechin/anaconda3/lib/python3.8/site-packages (from zope.interface>=4.4.2->Twisted>=17.5.0->vtk->pyvista>=0.25.0->pyvistaqt) (52.0.0.post20210125)
Installing collected packages: pyvistaqt
Successfully installed pyvistaqt-0.5.0

到这儿截止,大家所必须 的软件就大部分安裝完成了。

实例检测

到这儿截止大家能看下这一库的运作实际效果。

画单独圆球

最先实行一个画球的简易实例,这儿一般全是在jupyter notebook上完成的,pyvista针对jupyter notebook有不错的适用。

import pyvista as pv
sphere = pv.Sphere()
sphere.plot(jupyter_backend='static')

运作的实际效果以下:

pyvistaqt实例

这儿是一个官方网给予的弹出式窗口的制图计划方案:

from threading import Thread
import time
import numpy as np
import pyvista as pv
import pyvistaqt as pvqt
from pyvista import examples


globe = examples.load_globe()
globe.point_arrays['scalars'] = np.random.rand(globe.n_points)
globe.set_active_scalars('scalars')


plotter = pvqt.BackgroundPlotter()
plotter.add_mesh(globe, lighting=False, show_edges=True, texture=True, scalars='scalars')
plotter.view_isometric()

# shrink globe in the background
def shrink():
    for i in range(50):
        globe.points *= 0.95
        # Update scalars
        globe.point_arrays['scalars'] = np.random.rand(globe.n_points)
        time.sleep(0.5)

thread = Thread(target=shrink)
thread.start()

实行后会弹出来一个pyqt的对话框以下所显示:

这一图实际上 是一个动态图片,可是qt的这一计划方案好像不可以在页面上立即导出来gif,这一点较为遗憾。但是在pyvista的api文档中,实际上 是包括导出来gif视频和mp4视频的,有关插口能够 参照:GIF转化成实例和MP4转化成实例这两个实例。

多控制模块数据可视化

在pyvista里边可以用MultiBlock将有关的控制模块都集成化起來,例如这一实例中集成化了2个圆球,实际上 应用的方式也非常简单,便是把建立的目标归纳到一个目录中:

import pyvista as pv
sphere1 = pv.Sphere(radius=0.1, center=(0, 0, 0))
sphere2 = pv.Sphere(radius=0.1, center=(0, 0, 1))
data = [sphere1,sphere2]
blocks = pv.MultiBlock(data)
blocks.plot(jupyter_backend='static',show_axes=1)

转化成的結果如下图所显示:

必须 留意的是,由于这儿都或是静态图片,三维的角度不能调节,因而假如座标设定不合理得话,有可能造成2个圆球的角度恰好重叠,看上去就只有一个圆球。

多控制模块数据可视化用时

根据以上的MultiBlock,我们可以很便捷的转化成一大堆的数据信息,可是这儿数据可视化的速度也是大家迫不得已考虑到的一个要素,因此这儿大家试着一个1000个圆球的数据可视化,并輸出時间:

import pyvista as pv
import numpy as np
import time
start_time=time.time()
data = [pv.Sphere(radius=0.01, center=(np.random.random(), np.random.random(), np.random.random())) for i in range(1000)]
blocks = pv.MultiBlock(data)
blocks.plot(jupyter_backend='static',show_axes=1)
end_time=time.time()
print ('The time cost of ploting {} spheres is: {}s'.format(len(data),end_time-start_time))

转化成的結果以下:

历经全过程统计分析,用时接近10s。

The time cost of ploting 1000 spheres is: 9.896512746810913s

这实际上 是一个较慢的速率,令人有点儿忧虑啊,针对一些几十万的管理体系,那数据可视化時间不可冲一天来到,这还不包含正中间的时间格式。

动态性绘图工具

这儿要采用大家以前安裝的一个软件ipygany,能够 在jupyter notebook中表明出去一个动态性的绘图工具,那样大家就可以用电脑鼠标去拖拽这一三维图,能看不一样的角度,以下是一个简易的单圆球实例:

import pyvista as pv
sphere = pv.Sphere()
plotter = pv.Plotter(notebook=True)
plotter.add_mesh(sphere)
plotter.show(jupyter_backend='ipygany')

可视化效果图大约那样,仅有在jupyter notebook中才可以见到实际效果:

最终填补一个自身写的简易实例,能够 在控制面板上画2个不一样部位的三维球,操作方法是立即将2个目标加起來,这一便是python中一些法术涵数的优点了,十分的个性化:

import pyvista as pv
plotter = pv.Plotter(notebook=True)
plotter.add_mesh(pv.Sphere(radius=0.3,center=(0,0,0)) pv.Sphere(radius=0.3,center=(0,0,1)))
plotter.show(jupyter_backend='ipygany')

数据可视化的实际效果大约以下:

那麼到这儿,必须 将的基本上测试用例就详细介绍进行,事后大量的作用,大伙儿能够 自主探寻。

汇总概述

文中根据对pyvista这一相对性“小众”的python三维可视化专用工具的探索,汇总了安裝与基本上的应用实例,包含单控制模块、多控制模块、静态数据图、动态性绘图工具、gif和mp4视频的导出来等。整体而言pyvista是一款3D渲染实际效果非常好的可视化软件,可是特性相对而言沒有那麼丰厚,针对经营规模并不大的管理体系或是一个十分功能强大的专用工具,强烈推荐应用。

版权声明

文中先发连接为:https://www.cnblogs.com/dechinphy/p/pyvista.html

创作者ID:DechinPhy

大量原著小说文章内容请参照:https://www.cnblogs.com/dechinphy/

打赏主播专用型连接:https://www.cnblogs.com/dechinphy/gallery/image/379634.html

腾讯云服务栏目同歩:https://cloud.tencent.com/developer/column/91958

“留一手”加重内卷,“讲不清”浪费时间,错过良好的机会哦!。

评论(0条)

刀客源码 游客评论