- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想根据采用离散值的另一个值(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.show() 之前尝试过这一行:
mySurf.actor.mapper.interpolate_scalars_before_mapping = True
渲染效果更好,但绿点变成了绿条。
最佳答案
我通过使用 scipy 最近邻插值并按对象的单元格使用一种颜色找到了答案。
from mayavi import mlab
import numpy as np
import scipy.interpolate
# 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(x,y,z ,values)
# the surface i am interested on
contour = mlab.pipeline.contour(src)
contour.filter.contours= [2.8,]
# I extract points that form my surface
PtsCoord = contour.outputs[0].points.to_array()
# then the variable that contains the indices of the points forming triangles.
PolyAndTriIDs = contour.outputs[0].polys.to_array()
PolyAndTriIDs = PolyAndTriIDs.reshape(PolyAndTriIDs.size/4,4)
# Coordinates of each triangle
x1,y1,z1 = PtsCoord[PolyAndTriIDs[:,1]].T
x2,y2,z2 = PtsCoord[PolyAndTriIDs[:,2]].T
x3,y3,z3 = PtsCoord[PolyAndTriIDs[:,3]].T
# I interpolate the color value at the center of triangles with the Nearest-neighbour interpolation method
interp0 = scipy.interpolate.NearestNDInterpolator( (x.ravel(),y.ravel(),z.ravel()), colorvalues.ravel() )
result0 = interp0((np.mean((x1,x2,x3),0),np.mean((y1,y2,y3),0),np.mean((z1,z2,z3),0)))
# Displaying with triangular_mesh and color given by cell scalar value
mesh = mlab.triangular_mesh(PtsCoord[:,0], PtsCoord[:,1], PtsCoord[:,2], PolyAndTriIDs[:,1:])
cell_data = mesh.mlab_source.dataset.cell_data
cell_data.scalars = result0
cell_data.scalars.name = 'Cell data'
cell_data.update()
mesh.actor.mapper.scalar_mode = 'use_cell_data'
mesh.module_manager.scalar_lut_manager.lut.table = np.array([[255,0,0,255],[0,255,0,255],[0,0,255,255]])
mesh.module_manager.scalar_lut_manager.use_default_range = False
mesh.module_manager.scalar_lut_manager.data_range = [ 0., 2.]
mlab.colorbar(title='ID', orientation='vertical', nb_labels=3)
结果不太流畅,但更相关。
关于python - mayavi 在表面上映射一个离散的颜色条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26428645/
如何在 Flutter 中使 slider 离散看起来像上图? slider discrete 最佳答案 使用 divisions Slider 的属性(property)小部件将其分成相等的部分,然
我正在创建一个带有颜色条的散点图 plt.scatter(X, Y, c=Z) plt.colorbar() plt.show() plt.close() 其中 X 和 Y 是 float 组,Z 是
我刚刚在 android studio 中发现了 seekbar 离散小部件,我发现它非常有用,但我不知道如何删除步骤指示器,或者用更合适的可绘制对象更改它们。 有人设法做到了吗? 这是我当前搜索栏的
问题 请注意以下问题:巫师可以创建和销毁 rune 。创建一个新的 rune 需要消耗与先前创建的 rune 数量成比例的法力。摧毁 rune 会恢复创建 rune 所用的法力。下面,我提出一个可能的
我正在尝试使用 ggplot2 中的 sf 和 geom_sf 制作 map ,其中一组点数据使用连续颜色比例(-1 到 1),一组线数据使用离散比例(a、b、c、d)着色。但是,当我在同一张 map
我正在尝试在具有连续状态(dim.= 20)和离散操作(3 个可能的操作)的环境中找到最佳策略。并且有一个特定的时刻:对于最佳策略,一个操作(称为“操作 0”)的选择频率应比其他两个操作高得多(频率约
仅使用 x-y 位置移动绘制圆弧的最佳方法是什么?例如,假设我想在点 (4,4) 处绘制一个半径为 4 的圆。让我们看看我的“抽屉”从 (4,0) 开始,每个方向的分辨率为 0.1 步。我将如何创建一
我正在使用一个使用广义加法模型的随机站点级效应来拟合一个模型,该模型在 mgcv 中实现。 R 包。我一直在使用函数 gam() 执行此操作但是,为了加快速度,我需要转到 bam()框架,与gam()
这个问题在这里已经有了答案: Make a line separated by group in bar chart (3 个答案) 关闭上个月。 我正在尝试使用 ggplot2 在条形图的每个条上
这个问题在这里已经有了答案: Make a line separated by group in bar chart (3 个答案) 关闭上个月。 我正在尝试使用 ggplot2 在条形图的每个条上
是否可以同时使用 Intel HD 4000 集成显卡和独立 GPU,OpenCL(或 CUDA)作为设备,CPU 作为主机?我想要一些代码在集成显卡上运行,而其他代码同时在我的 GPU 上运行。 最
我是一名优秀的程序员,十分优秀!