Можно ли изменить цвет изо-поверхности в зависимости от высоты точек (в python/mayavi)? Я могу создать визуализацию изо-поверхности с помощью своего скрипта, но я не знаю, как заставить iso_surface менять цвет по оси z, чтобы он был, скажем, черным внизу и белым вверху графика. Мне нужно это, чтобы понять визуализацию, когда она просматривается прямо над графиком. Если вы знаете какой-либо другой способ добиться этого, пожалуйста, дайте мне знать. Я хочу показать только один график iso_surface.
Изменение цвета в зависимости от высоты в Mayavi iso_surface
Ответы (1)
Мне удалось это сделать, объединив некоторый код из примеров http://docs.enthought.com/mayavi/mayavi/auto/example_atomic_orbital.html#example-atomic-orbital и http://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. Я надеюсь, что это помогает кому-то.
person
hmhmhmmm
schedule
02.04.2013