Mayavi如何显示轴网格

问题描述 投票:1回答:1

在Mayavi中,我想在下图中看到轴的网格

# 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()

就像在Matlab中一样

The axes grid is shown as I want here

我必须在Mayavi使用哪个命令来实现这一目标?

python mayavi mayavi.mlab
1个回答
0
投票

我的建议是使用用户定义的过滤器,如来自CubeAxesActorVTK(它看起来比默认Mayavi中的Axes过滤器更完整)。在Mayavi中哪个会转化为类似的东西

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

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

但似乎Mayavi不喜欢这个过滤器

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

我不确定它是否与我的VTK版本有关,但你可能会尝试

© www.soinside.com 2019 - 2024. All rights reserved.