1

是否可以根据点的高度(在 python / mayavi 中)更改等值面的颜色?我可以用我的脚本创建一个 iso_surface 可视化,但我不知道如何使 iso_surface 用 z 轴改变颜色,这样我们就可以说底部是黑色,顶部是白色。当从图形的正上方查看可视化时,我需要它来理解可视化。如果您知道实现此目的的任何其他方法,请也告诉我。我只想显示一个 iso_surface 图。

4

1 回答 1

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 中可能出现的错误。我希望这可以帮助别人。

于 2013-04-02T14:20:28.183 回答