简体   繁体   English

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

[英]Draw multiple lines with specific line color in Mayavi

I followed http://docs.enthought.com/mayavi/mayavi/auto/example_plotting_many_lines.html to draw multiple point-to-point lines in 3D. 我遵循了http://docs.enthought.com/mayavi/mayavi/auto/example_plotting_many_lines.html在3D中绘制多条点对点线。 It works, but i need to color each of the lines according to some scalar value. 它有效,但是我需要根据一些标量值为每行着色。

How can i assign such a scalar value on a line-per-line basis? 如何在每行基础上分配这样的标量值?

The tutorial you linked does use scalars to specify the line colors (using the "accent" map). 您链接的教程确实使用标量来指定线条颜色(使用“重点”图)。 When calling mlab.pipeline.scalar_scatter(x,y,z,s) , scalars go in s . 调用mlab.pipeline.scalar_scatter(x,y,z,s) ,标量进入s

Did you mean to ask something more? 你是想问更多吗?

Here's a workaround that involves duplicating each point with one dup for every time it appears in an edge: 这是一种变通方法,涉及到每次出现在边缘中时都用一个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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM