在Mayavi中用特定的线颜色绘制多条线

2024-04-20 09:13:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我跟随http://docs.enthought.com/mayavi/mayavi/auto/example_plotting_many_lines.html在3D中绘制了多条点到点的线。 它可以工作,但我需要根据一些标量值给每一行上色。在

我如何在每行的基础上分配这样的标量值?在


Tags: comhttpdocsautoexamplehtml绘制plotting
2条回答

这里有一个解决方法,它涉及到在边上每次出现一个dup来复制每个点:

def colorize_edges(points, edge_indices, edge_colors):
    assert points.ndim == 2
    assert points.shape[1] == 3
    assert edge_indices.ndim == 2
    n_edges = edge_indices.shape[0]
    assert edge_indices.shape[1] == 2
    edge_indices = edge_indices.astype(int)
    assert edge_colors.ndim == 1
    assert edge_colors.shape[0] == n_edges
    x, y, z = points[:, 0], points[:, 1], points[:, 2]
    i, j = edge_indices[:, 0], edge_indices[:, 1]
    x = np.hstack([x[i], x[j]])
    y = np.hstack([y[i], y[j]])
    z = np.hstack([z[i], z[j]])
    c = np.hstack([c, c])
    src = mlab.pipeline.scalar_scatter(x, y, z, c)
    connections = np.vstack([i, j+n_edges]).T
    src.mlab_source.dataset.lines = connections
    surf = mlab.pipeline.surface(src, line_width=1.0)
    mlab.show()

链接的教程确实使用标量指定线颜色(使用“重音”贴图)。当调用mlab.pipeline.scalar_scatter(x,y,z,s)时,标量进入s

你是不是想多问点什么?

相关问题 更多 >