【发布时间】:2017-06-28 06:17:41
【问题描述】:
我正在尝试构建一个使用 mlab iso_surface 模块的简单 Mayavi 脚本应用程序。
但是,当我运行我的应用程序时,它会弹出两个窗口,一个显示我的 mayavi iso_surface 图,另一个显示空白的“编辑属性”窗口。 “编辑属性”窗口的指定视图布局中似乎没有显示 mayavi 场景。
所以我的问题是:为什么 mayavi iso_surface 场景没有出现在视图布局中,我如何将其放入其中?
下面粘贴了一个显示此行为的简单测试脚本。我在 Windows 10 系统上使用 Canopy 版本:2.1.1.3504(64 位)、python 3.5.2。
[注意:我已经修改了我的原始问题以包含另一个问题。如何使用 Range 对象 (mult_s) 的输入更新“s”数据?我在下面尝试过这样做,但没有成功。它抛出:TraitError: Cannot set the undefined 's' attribute of a 'ArraySource' object.]
class Isoplot1(HasTraits):
scene = Instance(MlabSceneModel, ())
mult_s = Range(1, 5, 1)
@on_trait_change('scene.activated')
def _setup(self):
# Create x, y, z, s data
L = 10.
x, y, z = np.mgrid[-L:L:101j, -L:L:101j, -L:L:101j]
self.s0 = np.sqrt(4 * x ** 2 + 2 * y ** 2 + z ** 2)
# create the data pipeline
self.src1 = mlab.pipeline.scalar_field(x, y, z, self.s0)
# Create the plot
self.plot1 = self.scene.mlab.pipeline.iso_surface(
self.src1, contours=[5, ], opacity=0.5, color=(1, 1, 0)
)
@on_trait_change('mult_s')
def change_s(self):
self.src1.set(s=self.s0 * self.mult_s)
# Set the layout
view = View(Item('scene',
editor=SceneEditor(scene_class=MayaviScene),
height=400, width=600, show_label=False),
HGroup('mult_s',),
resizable=True
)
isoplot1 = Isoplot1()
isoplot1.configure_traits()
【问题讨论】: