Mayavi 中的时间相关数据
Time dependent data in Mayavi
假设我有一个这样的 4d numpy 数组:my_array[x,y,z,t]
.
有没有一种简单的方法可以将整个数组加载到 Mayavi 中,然后只需选择我要调查的 t
?
我知道可以为数据设置动画,但我想旋转我的图形 "on the go"。
可以设置带有输入框的对话,您可以在其中设置t
。
你必须使用 traits.api,它可能看起来像这样:
from traits.api import HasTraits, Int, Instance, on_trait_change
from traitsui.api import View, Item, Group
from mayavi.core.ui.api import SceneEditor, MlabSceneModel, MayaviScene
class Data_plot(HasTraits):
a = my_array
t = Int(0)
scene = Instance(MlabSceneModel, ())
plot = Instance(PipelineBase)
@on_trait_change('scene.activated')
def show_plot(self):
self.plot = something(self.a[self.t]) #something can be surf or mesh or other
@on_trait_change('t')
def update_plot(self):
self.plot.parent.parent.scalar_data = self.a[self.t] #Change the data
view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
show_label=False),
Group('_', 't'),
resizable=True,
)
my_plot = Data_plot(a=my_array)
my_plot.configure_traits()
如果您愿意,也可以使用命令 Range
而不是 Int
来设置滑块。
假设我有一个这样的 4d numpy 数组:my_array[x,y,z,t]
.
有没有一种简单的方法可以将整个数组加载到 Mayavi 中,然后只需选择我要调查的 t
?
我知道可以为数据设置动画,但我想旋转我的图形 "on the go"。
可以设置带有输入框的对话,您可以在其中设置t
。
你必须使用 traits.api,它可能看起来像这样:
from traits.api import HasTraits, Int, Instance, on_trait_change
from traitsui.api import View, Item, Group
from mayavi.core.ui.api import SceneEditor, MlabSceneModel, MayaviScene
class Data_plot(HasTraits):
a = my_array
t = Int(0)
scene = Instance(MlabSceneModel, ())
plot = Instance(PipelineBase)
@on_trait_change('scene.activated')
def show_plot(self):
self.plot = something(self.a[self.t]) #something can be surf or mesh or other
@on_trait_change('t')
def update_plot(self):
self.plot.parent.parent.scalar_data = self.a[self.t] #Change the data
view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
show_label=False),
Group('_', 't'),
resizable=True,
)
my_plot = Data_plot(a=my_array)
my_plot.configure_traits()
如果您愿意,也可以使用命令 Range
而不是 Int
来设置滑块。