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

时间:2015-01-30 10:44:51

标签: python mayavi

您好我想使用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,看看是否有某个地方我可以关闭它,但我似乎无法找到它

2 个答案:

答案 0 :(得分:0)

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

在最后一行,更改

mlab.pipeline.scalar_cut_plane(d)

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

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

转到管道菜单中的ScalarCutPlane,然后通过取消选中“ImplicitPlane”选项卡中的“enable”来禁用窗口小部件。

......你去了

答案 1 :(得分:0)

您可以通过添加以下内容使它变得更好

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

现在您可以先将其放置在所需位置了。