2013-03-26 73 views
1

根据点的高度(在python/mayavi中),是否可以改变iso-surface的颜色? 我可以用我的脚本创建一个iso-surface可视化,但是我不知道如何用z轴改变iso_surface的颜色,这样我们可以说黑色在底部,白色在顶部。 我需要这个以便从图上方直观地看到可视化。 如果你知道任何其他方式来实现这一点,请让我知道。 我只想显示一个iso_surface图。根据Mayavi中的高度改变颜色iso_surface

回答

1

我设法通过结合来自例子http://docs.enthought.com/mayavi/mayavi/auto/example_atomic_orbital.html#example-atomic-orbitalhttp://docs.enthought.com/mayavi/mayavi/auto/example_custom_colormap.html的一些代码来做到这一点。基本上你必须像在原子轨道的例子中一样创建一个表面,然后根据x改变颜色。您必须为x创建一个数组值。我的代码(相关部分):

#src.image_data.point_data.add_array(np.indices(list(self.data.shape)[self.nx,self.ny,self.nz])[2].T.ravel()) 
    src.image_data.point_data.add_array(np.indices(list(self.data.shape))[0].T.ravel()) 
    src.image_data.point_data.get_array(1).name = 'z' 
    # Make sure that the dataset is up to date with the different arrays: 
    src.image_data.point_data.update() 
    # We select the 'scalar' attribute, ie the norm of Phi 
    src2 = mlab.pipeline.set_active_attribute(src, point_scalars='scalar') 
    # Cut isosurfaces of the norm 
    contour = mlab.pipeline.contour(src2) 
    # contour.filter.contours=[plotIsoSurfaceContours] 
    # contour.filter.contours=[plotIsoSurfaceContours[0]] 
    min_c = min(contour.filter._data_min * 1.05,contour.filter._data_max) 
    max_c = max(contour.filter._data_max * 0.95,contour.filter._data_min) 
    plotIsoSurfaceContours = [ max(min(max_c,x),min_c) for x in plotIsoSurfaceContours ] 
    contour.filter.contours= plotIsoSurfaceContours 

    # Now we select the 'angle' attribute, ie the phase of Phi 
    contour2 = mlab.pipeline.set_active_attribute(contour, point_scalars='z') 
    # And we display the surface. The colormap is the current attribute: the phase. 
    # mlab.pipeline.surface(contour2, colormap='hsv') 
    xxx = mlab.pipeline.surface(contour2, colormap='gist_ncar') 
    colorbar = xxx.module_manager.scalar_lut_manager 
    colorbar.reverse_lut = True 
    lut = xxx.module_manager.scalar_lut_manager.lut.table.to_array() 
    lut[:,-1] = int(plotIsoSurfaceOpacity * 254) 
    xxx.module_manager.scalar_lut_manager.lut.table = lut 
    # mlab.colorbar(title='Phase', orientation='vertical', nb_labels=3) 

self.data是我的数据,以及原因不明,如果你想设置你的表面的不透明度必须先颠倒的LUT,然后设置不透明度。乘以254而不是255是为了避免mayavi中可能的错误。 我希望这可以帮助某人。