15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python3.6 で Mayaviを動かす

Last updated at Posted at 2018-01-13

##はじめに
Pythonで3D表示させるために、比較的手軽に利用できるMayavi を利用しました。
MayaviはVTKのバージョン依存がありPython3で、Mayaviを動作させるのに結構はまったので記事を書きました。

##動作環境
Ubuntu 16.04.2 LTS
python 3.6.4
pyenv
virtualenv
anaconda

##環境構築
apt-getで必要なライブラリをインストールします

sudo apt-get install -y libglib2.0-0 libxext6 libsm6 libxrender1 gtk3.0

anacondaでpython3.6.4環境を準備します

conda create -n mayenv python=3.6.4 anaconda
pyenv activate anaconda3-4.3.1/envs/mayenv

必要なパッケージをインストールします。(VTKのバージョン7.1.1がインストールされる)

conda install -y -c conda-forge qt vtk pyvtk pyside envisage mesalib mayavi
conda install -y -c ajsrk traitsui
pip install scipy

##動作確認
サンプルプログラムを動作させ、3Dオブジェクトが表示されれば完了です

from numpy import pi, sin, cos, mgrid
dphi, dtheta = pi/250.0, pi/250.0
[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
x = r*sin(phi)*cos(theta)
y = r*cos(phi)
z = r*sin(phi)*sin(theta)

from mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()

Screenshot from 2018-01-13 20-07-10.png

###参考にしたサイト
http://docs.enthought.com/mayavi/mayavi/mlab.html#a-demo
https://stackoverflow.com/questions/19138418/get-mayavi-working-with-python-3

15
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?