【问题标题】:Scalar fields visualisation in PythonPython中的标量字段可视化
【发布时间】:2014-11-17 10:33:09
【问题描述】:

我需要在 Python 中可视化几个重叠的标量字段。我找到了mayavi 库来做这种情节。问题是我不明白如何为标量字段自定义颜色图。我的想法是为每个字段设置一种颜色的阴影。我尝试采用an example,但它不起作用。这是我使用红色阴影可视化标量场的代码:

import numpy as np
from mayavi import mlab

x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

src = mlab.pipeline.scalar_field(s)
volume = mlab.pipeline.volume(src)

lut = np.zeros((256, 4), np.uint8)
lut[:,-1] = 255
lut[:, 0] = np.linspace(0, 255, 256)

volume.module_manager.scalar_lut_manager.lut.table = lut

mlab.draw()
mlab.view(40, 85)

mlab.show()

但是,输出图始终带有标准的蓝红查找表。

【问题讨论】:

  • 您找到解决方案了吗?我也有类似的问题:stackoverflow.com/questions/36946231/…
  • 嗯,当我尝试将table 重新分配给修改后的lut 时,它什么也没做。我要提交错误报告。
  • 据我所知,这似乎是一个错误。我在这里提交了一个错误报告:github.com/enthought/mayavi/issues/371
  • 不,我没能解决这个问题......让我们看看你的错误报告将如何评论。

标签: python 3d visualization mayavi


【解决方案1】:

我无法找到使用 lut_manager 的解决方案,但下面的解决方案,遵循 this github reply 对我有用。

import numpy as np
from mayavi import mlab
# import color transfer function from vtk
from tvtk.util import ctf
# import matlab colormaps
from matplotlib.pyplot import cm

x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

src = mlab.pipeline.scalar_field(s)
volume = mlab.pipeline.volume(src)

# save the color transfer function of the current volume
c = ctf.save_ctfs(volume._volume_property)
# change the alpha channel as needed
c['alpha'][1][1] = 0.5
# change the color points to another color scheme
# in this case 'magma'
c['rgb']=[[a[0],a[1],a[2],cm.magma.colors.index(a)/255] for a in cm.magma.colors]
# load the new color transfer function
ctf.load_ctfs(c, volume._volume_property)
# signal for update
volume.update_ctf = True

mlab.show()

【讨论】:

    猜你喜欢
    • 2017-10-15
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多