複数のmlabシーンモデルの例¶
複数のシーンが埋め込まれたダイアログボックスの例.
mlabを使用して複数の埋め込みシーンを使用する場合は,プロットに使用するシーンを,現在のシーンを使用するmlab関数に渡すように十分注意してください.この例では,失敗すると,最後に作成された1つのシーンのみが使用されます.
コツは, MlabSceneModel の 'mayavi_scene' 属性をキーワード引数としてmlab関数に渡すことです.
mlabシーンをダイアログに埋め込む例については,以下も参照してください.例えば Mlab対話型ダイアログの例 および Lorenz uiの例 およびユーザマニュアルのセクション 特性ダイアログへのMayaviシーンの埋め込み .
Pythonソースコード: multiple_mlab_scene_models.py
import numpy as np
from traits.api import HasTraits, Instance, Button, \
on_trait_change
from traitsui.api import View, Item, HSplit, Group
from mayavi import mlab
from mayavi.core.ui.api import MlabSceneModel, SceneEditor
class MyDialog(HasTraits):
scene1 = Instance(MlabSceneModel, ())
scene2 = Instance(MlabSceneModel, ())
button1 = Button('Redraw')
button2 = Button('Redraw')
@on_trait_change('button1')
def redraw_scene1(self):
self.redraw_scene(self.scene1)
@on_trait_change('button2')
def redraw_scene2(self):
self.redraw_scene(self.scene2)
def redraw_scene(self, scene):
# Notice how each mlab call points explicitly to the figure it
# applies to.
mlab.clf(figure=scene.mayavi_scene)
x, y, z, s = np.random.random((4, 100))
mlab.points3d(x, y, z, s, figure=scene.mayavi_scene)
# The layout of the dialog created
view = View(HSplit(
Group(
Item('scene1',
editor=SceneEditor(), height=250,
width=300),
'button1',
show_labels=False,
),
Group(
Item('scene2',
editor=SceneEditor(), height=250,
width=300, show_label=False),
'button2',
show_labels=False,
),
),
resizable=True,
)
m = MyDialog()
m.configure_traits()