Single line with multiple radii with Mayavi

a 夏天 提交于 2021-01-29 02:33:05

问题


I am trying to plot a single line (or tube) in Mayavi that has a non-constant width or radius. This seems like a simple task though I may not be understanding what is happening behind the scenes well enough to make this happen.

The following code creates the line I want, and I am able to scale by color; however, I would also like to scale by width.

import mayavi.mlab as mlab
import numpy as np

x = range(100)
y = range(100)
z = range(100)
s = np.random.uniform(0, 1, 100)

mlab.plot3d(x, y, z, s, tube_radius=10)

I don't have an image of the desired output as I am unable to create it, though it would essentially be the preceding image scaled by radius instead of color, so that some areas of the line would be wider than other areas. One possible solution would be to use the tube_radius parameter and plot each section individually, though this really seems like poor practice as the lines can get quite long and have many different sections.


回答1:


In the GUI, you can go to the Tube pipeline and use Vary_radius = 'vary_radius_by_scalar'

In the script you can do

import mayavi.mlab as mlab
import numpy as np

x = range(100)
y = range(100)
z = range(100)
s = np.random.uniform(0, 1, 100)

t = mlab.plot3d(x, y, z, s, tube_radius=10)
t.parent.parent.filter.vary_radius = 'vary_radius_by_scalar'

Since the parent of the surface is the Module manager (colors, etc) and its parent is the Tube pipeline



来源:https://stackoverflow.com/questions/41768306/single-line-with-multiple-radii-with-mayavi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!