【问题标题】:Get colour at specific point in a scalar mesh with mayavi mlab使用 mayavi mlab 在标量网格中的特定点获取颜色
【发布时间】:2022-09-28 21:01:07
【问题描述】:

我正在使用mayavi.mlab.mesh 绘制一个带有与之关联的标量场的球体。鉴于该球体上的一些坐标,我还想绘制点与该点的网格表面颜色相同.

例如:

import numpy as np
from mayavi import mlab

# Here I construct the spherical mesh grid
phi = np.linspace(0, np.pi, 100)
theta = np.linspace(0, 2*np.pi, 100)
phi, theta = np.meshgrid(phi, theta)

x = (np.sin(phi) * np.cos(theta)).astype(np.float32)
y = (np.sin(phi) * np.sin(theta)).astype(np.float32)
z = (np.cos(phi)).astype(np.float32)

# Let\'s use a random scalar field to demonstrate
s = np.random.randn(*x.shape)

# Now we plot the sphere surface
plot = mlab.mesh(x, y, z, scalars=s, colormap=\'jet\')

# Let\'s create some random points on the sphere that we want to additionally
# plot as mlab.points3d
pts = np.random.randn(10, 3)
pts = pts / np.linalg.norm(pts)

我想用与下面的网格表面相同的颜色绘制pts,但我不确定该怎么做。

    标签: python mayavi mayavi.mlab


    【解决方案1】:

    通过阅读一些类似的帖子,我在这种情况下找到了答案。

    # First scale the scalar field to be between [0, 1]
    s_scaled = ((s - np.min(s)) / (np.max(s) - np.min(s)))
    
    # Plot the points, ensuring the colormap is the same as used with the mesh
    nodes = mlab.points3d(x, y, z, scale_factor=0.05, colormap='jet')
    
    # Set scale mode to scale by vector so that the points do not change size
    nodes.glyph.scale_mode = 'scale_by_vector'
    
    # Finally set the scalar values of the points to your scaled s vector
    nodes.mlab_source.dataset.point_data.scalars = s_scaled
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 2013-09-03
      • 2012-10-07
      • 2016-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多