【问题标题】:Change color depending on height in Mayavi iso_surface根据 Mayavi iso_surface 中的高度更改颜色
【发布时间】:2013-03-26 13:21:11
【问题描述】:

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

【问题讨论】:

    标签: python vtk enthought mayavi


    【解决方案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 中可能出现的错误。 我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-11-04
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      相关资源
      最近更新 更多