Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mayavi how to show the axes grid

In Mayavi I would like to see the grid of the axes in the following plot

# Source: <<https://scicomp.stackexchange.com/a/23148/10048>>.
import numpy as np
from mayavi import mlab

# Test data: Matlab `peaks()`
x, y = np.mgrid[-3:3:50j, -3:3:50j]
z = 3*(1 - x)**2 * np.exp(-x**2 - (y + 1)**2) \
   - 10*(x/5 - x**3 - y**5)*np.exp(-x**2 - y**2) \
   - 1./3*np.exp(-(x + 1)**2 - y**2) 

mlab.figure(bgcolor=(1, 1, 1))  # Make background white.
surf = mlab.surf(x, y, z, colormap='RdYlBu', warp_scale=0.3, representation='wireframe', line_width=0.5)
mlab.outline(color=(0, 0, 0))
axes = mlab.axes(color=(0, 0, 0), nb_labels=5)
axes.title_text_property.color = (0.0, 0.0, 0.0)
axes.title_text_property.font_family = 'times'
axes.label_text_property.color = (0.0, 0.0, 0.0)
axes.label_text_property.font_family = 'times'
# mlab.savefig("vector_plot_in_3d.pdf")
mlab.gcf().scene.parallel_projection = True  # Source: <<https://stackoverflow.com/a/32531283/2729627>>.
mlab.orientation_axes()  # Source: <<https://stackoverflow.com/a/26036154/2729627>>.
mlab.show()

like in Matlab

The axes grid is shown as I want here

Which command do I have to employ in Mayavi to achieve this?

like image 922
Adriaan Avatar asked Feb 25 '19 09:02

Adriaan


1 Answers

My suggestion would be to use a user defined filter like CubeAxesActor from VTK (which seems more complete than the Axes filter in default Mayavi). Which in Mayavi would translate into something like

...
from mayavi import mlab
from tvtk.api import tvtk

...
# Load data
...
mlab.pipeline.user_defined(data, filter=tvtk.CubeAxesActor())
...

But it seems Mayavi does not like this filter

traits.trait_errors.TraitError: Cannot set the undefined 'input_connection' attribute of a 'CubeAxesActor' object.

I'm not sure if it is related to my VTK version but you might try

like image 97
PerroNoob Avatar answered Sep 30 '22 19:09

PerroNoob