Question

I followed http://docs.enthought.com/mayavi/mayavi/auto/example_plotting_many_lines.html to draw multiple point-to-point lines in 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?

Was it helpful?

Solution

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.

Did you mean to ask something more?

OTHER TIPS

Here's a workaround that involves duplicating each point with one dup for every time it appears in an edge:

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top