嗨,我想用mayavi在剖切面上可视化结构化网格中的数据。在
为了举例说明这一点,我从ericjones编写的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_字段但我得到一个错误,说我需要将数据指定为数组。 我还搜索了gui,看看是否有什么地方可以关闭它,但似乎找不到
您可以简单地禁用小部件。但是请注意,这意味着您不能再在您的平面上拖动(但听起来您不想拥有此功能)
在最后一行,改变
与
^{pr2}$在GUI中也可以这样做。在
转到pipeline菜单中的ScalarCutPlane,然后取消选中“ImplicitPlane”选项卡中的“enable”来禁用小部件。在
……你就这样
相关问题 更多 >
编程相关推荐