import numpy as np
from mayavi import mlab
#建立数据
x,y = np.mgrid[-::200j,-::200j]
z = *np.sin(x*y)/(x*y)
#对数据进行可视化
mlab.figure(bgcolor=(,,))
surf = mlab.surf(z,colormap="cool") #cool使用冷色系
#更新视图并显示出来
mlab.show()
>>> x,y = np.mgrid[-::200j,-::200j]
>>> z = *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[-::200j,-::200j]
z = *np.sin(x*y)/(x*y)
#对数据进行可视化
mlab.figure(bgcolor=(,,))
surf = mlab.surf(z,colormap="cool")
#访问surf对象的LUT
#LUT是一个255*4的数组,列向量表示RGBA,每个值的范围从0-
lut = surf.module_manager.scalar_lut_manager.lut.table.to_array()
#增加透明度,修改alpha通道
lut[:,-] = np.linspace(,,) #修改列向量中A通道
surf.module_manager.scalar_lut_manager.lut.table = lut
#更新视图并显示出来
mlab.show()