科学计算三维可视化---Mlab基础(改变物体的外观颜色)

import numpy as np
from mayavi import mlab

#建立数据
x,y = np.mgrid[-10:10:200j,-10:10:200j]
z = 100*np.sin(x*y)/(x*y)
#对数据进行可视化
mlab.figure(bgcolor=(1,1,1))
surf = mlab.surf(z,colormap="cool")  #cool使用冷色系
#更新视图并显示出来
mlab.show()
>>> x,y = np.mgrid[-10:10:200j,-10:10:200j]
>>> z = 100*np.sin(x*y)/(x*y)  #是一个二维数据
>>> z
array([[-0.50636564, -1.00954046, -0.57671118, ..., -0.57671118,
        -1.00954046, -0.50636564],
       [-1.00954046, -0.58512546,  0.38643354, ...,  0.38643354,
        -0.58512546, -1.00954046],
       [-0.57671118,  0.38643354,  1.02032807, ...,  1.02032807,
         0.38643354, -0.57671118],
       ...,
       [-0.57671118,  0.38643354,  1.02032807, ...,  1.02032807,
         0.38643354, -0.57671118],
       [-1.00954046, -0.58512546,  0.38643354, ...,  0.38643354,
        -0.58512546, -1.00954046],
       [-0.50636564, -1.00954046, -0.57671118, ..., -0.57671118,
        -1.00954046, -0.50636564]])
>>>

import numpy as np
from mayavi import mlab

#建立数据
x,y = np.mgrid[-10:10:200j,-10:10:200j]
z = 100*np.sin(x*y)/(x*y)
#对数据进行可视化
mlab.figure(bgcolor=(1,1,1))
surf = mlab.surf(z,colormap="cool")
#访问surf对象的LUT
#LUT是一个255*4的数组,列向量表示RGBA,每个值的范围从0-255
lut = surf.module_manager.scalar_lut_manager.lut.table.to_array()
#增加透明度,修改alpha通道
lut[:,-1] = np.linspace(0,255,256)  #修改列向量中A通道
surf.module_manager.scalar_lut_manager.lut.table = lut

#更新视图并显示出来
mlab.show()

 

 

posted @ 2018-07-13 12:42  山上有风景  阅读(829)  评论(0编辑  收藏  举报