我想根据另一个取离散值的值(ID)来改变曲面的颜色(所以我需要一个离散的颜色条)。 在下面的简化示例中,我绘制了一个具有3个不同ID的球体:
0/左侧红色
2/中间蓝色
1/左边是绿色
但是通过下面的代码,我得到了一些奇怪的行为(绿点)在红色和蓝色之间的极限。 可能是因为插值!在
代码:
from mayavi import mlab
import numpy as np
# my dataset -simplified-
x,y,z = np.mgrid[-3:3:100j, -3:3:100j, -3:3:100j]
values = np.sqrt(x**2 + y**2 + z **2)
# my color values : the volume is divided in 3 sub-volumes along x taking
colorvalues=np.empty(values.shape)
colorvalues[0:33,:,:]=0.
colorvalues[33:66,:,:]=2.
colorvalues[66:,:,:] =1.
src = mlab.pipeline.scalar_field(values)
src.image_data.point_data.add_array(colorvalues.T.ravel())
src.image_data.point_data.get_array(1).name = 'myID'
src.image_data.point_data.update()
# the surface i am interested on
contour = mlab.pipeline.contour(src)
contour.filter.contours= [2.8,]
# to map the ID
contour2 = mlab.pipeline.set_active_attribute(contour, point_scalars='myID')
# And we display the surface The colormap is the current attribute: the ID.
mySurf=mlab.pipeline.surface(contour2)
# I change my colormap to a discrete one : R-G-B
mySurf.module_manager.scalar_lut_manager.lut.table = np.array([[255,0,0,255],[0,255,0,255],[0,0,255,255]])
mlab.colorbar(title='ID', orientation='vertical', nb_labels=3)
mlab.show()
我以前也试过这条线mlab.表演():
^{pr2}$渲染效果更好,但绿色点变成了绿色条纹。在
我已经找到了我的答案,使用了一个凌乱的最近邻插值和使用一个颜色的细胞我的对象。在
结果不那么平滑,但更具相关性。在
相关问题 更多 >
编程相关推荐