使用mayavi时如何去除scalar_cut_plane中的红框和白箭头?
How to remove the red frame and white arrow in scalar_cut_plane when using 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 看是否有什么地方可以关闭它,但我似乎找不到它
您可以简单地禁用该小部件。但是请注意,这意味着您不能再在飞机上拖动(但听起来您不想拥有此功能)
在最后一行,更改
mlab.pipeline.scalar_cut_plane(d)
和
cut = mlab.pipeline.scalar_cut_plane(d)
cut.implicit_plane.widget.enabled = False
也可以在 GUI 中执行此操作。
转到管道菜单中的 ScalarCutPlane,然后通过取消选中 "ImplicitPlane" 选项卡中的 "enable" 来禁用小部件。
...好了
您可以通过添加使其变得更好:
cut = mlab.pipeline.scalar_cut_plane(d)
input('Press any key to snap in . . .')
cut.implicit_plane.widget.enabled = False
现在您可以先放在想要的位置了。
您好,我想使用 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,然后通过取消选中 "ImplicitPlane" 选项卡中的 "enable" 来禁用小部件。
...好了
您可以通过添加使其变得更好:
cut = mlab.pipeline.scalar_cut_plane(d)
input('Press any key to snap in . . .')
cut.implicit_plane.widget.enabled = False
现在您可以先放在想要的位置了。