Mayavi points3d with different size and colors

前端 未结 3 2006
醉话见心
醉话见心 2021-01-04 03:46

Is it possible in mayavi to specify individually both the size and the colors of every point?

That API is cumbersome to me.

points3d(x, y, z...)
poi         


        
3条回答
  •  悲&欢浪女
    2021-01-04 04:25

    I agree that the API that Mayavi provides here is unpleasant. The Mayavi documentation suggests the following hack (which I have paraphrased slightly) to independently adjust the size and color of points.

    pts = mayavi.mlab.quiver3d(x, y, z, sx, sy, sz, scalars=c, mode="sphere", scale_factor=f)
    pts.glyph.color_mode = "color_by_scalar"
    pts.glyph.glyph_source.glyph_source.center = [0,0,0]
    

    This will display x,y,z points as spheres, even though you're calling mayavi.mlab.quiver3d. Mayavi will use the norm of sx,sy,sz vectors to determine the size the points, and will use the scalar values in c to index into a color map. You can optionally supply a constant size scaling factor, which will be applied to all the points.

    This is certainly not the most self-documenting code you'll ever write, but it works.

提交回复
热议问题