Mayavi how to show the axes grid

故事扮演 提交于 2021-02-07 07:12:05

问题


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

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


回答1:


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



来源:https://stackoverflow.com/questions/54863564/mayavi-how-to-show-the-axes-grid

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