Mayavi入门_乐理知识入门

环境,win7/10 64位, python3.x

1,安装 Mayavi4.6

原装的pip下载奇慢,先更换一下源,豆瓣的更新要比清华的快

首先在window的文件夹窗口输入 : %APPDATA%

然后在底下新建pip文件夹,然后到pip文件夹里面去新建个pip.ini,然后再里面输入内容

global]
timeout = 6000
index-url = https://pypi.douban.com/simple
trusted-host = pypi.douban.com

1.1 

pip install numpy

安装mayavi 4.6 会报错,Microsoft Visual C++ 14.0 is required

下载安装包即可,安装包

虽然只有3M大小,但是安装还是很费时间的,应该要下载很多东西吧。

pip install mayavi

还需要图形库,随便装PyQt还是wxPython

pip install PyQt5

安装完成

运行下面代码

# Create the data.
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 = sinm0*phi)**m1 + cosm2*phi)**m3 + sinm4*theta)**m5 + cosm6*theta)**m7
x = r*sinphi)*costheta)
y = r*cosphi)
z = r*sinphi)*sintheta)

# View it.
from mayavi import mlab
s = mlab.meshx, y, z)
mlab.show)

出现下图,成功!

Mayavi入门_乐理知识入门Mayavi入门_乐理知识入门

 再来一段有意思的代码,图片自己看

from numpy import exp, mgrid, log10

[x,y]=mgrid[0.01:1.0:0.01, 0.01:1.0:0.01]
z = 11*x*log10x)*y*y-1) + exp-25.*x-25./exp1))**2+25.**y-25/2.)**2)**3)/25

# View it.
from mayavi import mlab
s = mlab.meshx, y, z, colormap="copper")
s = mlab.meshx-0.9, y, z, colormap="copper")
mlab.show)

 

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注