使用mayavi时如何删除scalar_cut_plane中的红框和白色箭头



嗨,我想使用 mayavi 在切割平面的结构化网格中可视化数据。

为了举例说明这一点,我从 Eric Jones 编写的 http://docs.enthought.com/mayavi/mayavi/auto/example_structured_grid.html 中获得以下代码

#!/usr/bin/env python  
import numpy as np
from numpy import cos, sin, pi
from tvtk.api import tvtk
from mayavi import mlab
def generate_annulus(r=None, theta=None, z=None):
    # Find the x values and y values for each plane.
    x_plane = (cos(theta)*r[:,None]).ravel()
    y_plane = (sin(theta)*r[:,None]).ravel()
    # Allocate an array for all the points.  We'll have len(x_plane)
    # points on each plane, and we have a plane for each z value, so
    # we need len(x_plane)*len(z) points.
    points = np.empty([len(x_plane)*len(z),3])
    # Loop through the points for each plane and fill them with the
    # correct x,y,z values.
    start = 0
    for z_plane in z:
        end = start + len(x_plane)
        # slice out a plane of the output points and fill it
        # with the x,y, and z values for this plane.  The x,y
        # values are the same for every plane.  The z value
        # is set to the current z
        plane_points = points[start:end]
        plane_points[:,0] = x_plane
        plane_points[:,1] = y_plane
        plane_points[:,2] = z_plane
        start = end
    return points
# Make the data.
dims = (51, 25, 25)
# The coordinates
theta = np.linspace(0, 2*np.pi, dims[0])
# 'y' corresponds to varying 'r'
r = np.linspace(1, 10, dims[1])
z = np.linspace(0, 5, dims[2])
pts = generate_annulus(r, theta, z)
# Make the grid
sgrid = tvtk.StructuredGrid(dimensions=dims)
sgrid.points = pts
s = np.sqrt(pts[:,0]**2 + pts[:,1]**2 + pts[:,2]**2)
sgrid.point_data.scalars = np.ravel(s.copy())
sgrid.point_data.scalars.name = 'scalars'
d = mlab.pipeline.add_dataset(sgrid)
mlab.pipeline.scalar_cut_plane(d)
mlab.show()

但是,我想在保存情节时摆脱烦人的红框和白色箭头。我该怎么做?

我首先尝试使用模块mlab.pipeline.scalar_field来执行此操作,但是我收到一个错误,说我需要将数据指定为数组。我还搜索了 gui,看看是否有可以关闭它的地方,但我似乎找不到它

您可以简单地禁用小部件。但请注意,这意味着您不能再拖拽飞机了(但听起来您不想拥有此功能)

在最后一行中,更改

mlab.pipeline.scalar_cut_plane(d)

cut = mlab.pipeline.scalar_cut_plane(d)
cut.implicit_plane.widget.enabled = False

也可以在 GUI 中执行此操作。

转到管道菜单中的 ScalarCutPlane,然后通过取消选中"隐式平面"选项卡中的"启用"来禁用小部件。

。你去吧

您可以通过添加以下内容使其更好:

cut = mlab.pipeline.scalar_cut_plane(d)
input('Press any key to snap in . . .')
cut.implicit_plane.widget.enabled = False

现在您可以先放置在所需的位置。

相关内容

  • 没有找到相关文章

最新更新