Search code examples
pythonplot3dvtkmayavi

Change property of vtk object created with Mayavi library in python


So, I am completely new to the Mayavi library, I actually installed it just today because I need to plot some 3d data (matplotlib doesn't work very well with 3d plots). I can successfully generate a 3d object by using the mesh function (xig, yig, and zi are 2d vectors created with np.linspace and griddata):

from mayavi import mlab
mlab.mesh(xig, yig, zi, colormap='viridis')

This generates the nice figure: noedges

However, by playing around a little in the GUI, I found a nice option that enables the visualisation of edges:

yesedges

Which I like much more! This option is found under: Mayavi pipeline>Surface>Actor>Property>More options>Edge visibility

Now, since I would like to automatize the processing of a lot of data, I would like to do this change in the python script itslef, without having to manually go in the GUI everytime! But I don't understand how to do it...

Can anybody help? I did a lot of research, but I get very confused in the syntax (I am not used to object oriented programming), and in the concepts of "vtk object", "actor" and company.

Thanks


Solution

  • Ok, I finally managed to do it! The code is the following:

    surf = mlab.mesh(xig, yig, zi, colormap='viridis')
    surf.actor.property.edge_visibility = True
    surf.actor.property.edge_color = (1,1,1)
    surf.actor.property.line_width = 0.5
    

    I found it by trial and error, since this is not documented in the mayavi guide...