1

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)

enter image description here

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
johnchase
  • 13,155
  • 6
  • 38
  • 64

1 Answers1

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

PerroNoob
  • 843
  • 2
  • 16
  • 36
  • Thank you this answers my question I likely would not have figured this out with guidance. As a follow up is possible to color and radius separately? For instance if I wanted to change the tube radius by one vector and the color by a different vector? – johnchase Jan 20 '17 at 19:42
  • M.. I'm not sure if you can but maybe you can add an extra `scalar` to the VTK data. You can access the data in the script as `vtk_data = t.parent.parent.parent.parent.data` , which is a `PolyData` class. Then you could maybe add some data using some of the methods of that class( `add_array` or similar). Here is an example on how they add data to a `PolyData` clas sobject http://docs.enthought.com/mayavi/mayavi/auto/example_polydata.html – PerroNoob Jan 23 '17 at 15:21