How to draw a line in Python Mayavi?

Question:

How to draw a line in 3D space in Python Mayavi? Is there a function from MLAB module that allows me to specify the start and end point of the line which will be drawn?

Asked By: Luka

||

Answers:

Check the documentation for mayavi; 3d plotting is in the tutorials and documented here.
It’s part of mlab, mayavi.mlab.plot3d(*args, **kwargs).

The syntax is

plot3d(x, y, z, ...)
Answered By: jmetz

One important feature you can use when drawing lines is to represent them as a tube. The following example I used to draw the X, Y, Z axis along with the 3D figure (note that in my case the dimensions are big, so that you might want to adjust them):

import mayavi.mlab as mlab

black = (0,0,0)
white = (1,1,1)
mlab.figure(bgcolor=white)
mlab.plot3d([0, 1000], [0, 0], [0, 0], color=black, tube_radius=10.)
mlab.plot3d([0, 0], [0, 1500], [0, 0], color=black, tube_radius=10.)
mlab.plot3d([0, 0], [0, 0], [0, 1500], color=black, tube_radius=10.)
mlab.text3d(1050, -50, +50, 'X', color=black, scale=100.)
mlab.text3d(0, 1550, +50, 'Y', color=black, scale=100.)
mlab.text3d(0, -50, 1550, 'Z', color=black, scale=100.)
Answered By: Saullo G. P. Castro

The command plot3d always draws a regular polygon, but I need just one line segment between two given points (x1,y1,z1) and (x2,y2,z2).
Is there a simple way to do it in Mayavi?

Answered By: Leo137
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.