【问题标题】:Updating data of an Image Plane Widget更新图像平面小部件的数据
【发布时间】:2015-05-07 09:37:04
【问题描述】:

我正在研究不同矢量场的可视化。

为此,我使用 Python 2.7 中的 Mayavi 库(我认为)创建一个图像平面小部件 (IPW) 和一个滑块以在可视化打开时更改矢量场的数据,但我的 IPW 赢了不改变。

如果每次更改滑块时我都将 IPW 渲染为新的,它会起作用,但这不是我想要的。

有没有办法在程序运行时更改 IPW 的数据,而无需每次都渲染一个新的平面?

我写了以下代码:

import numpy as np
from mayavi import mlab
from matplotlib.scale import scale_factory
from traits.api import HasTraits, Range, Instance, Array, \
    on_trait_change
from traitsui.api import View, Item, Group
from mayavi.core.pipeline_base import PipelineBase
from mayavi.core.ui.api import MayaviScene, SceneEditor, \
            MlabSceneModel

class Modell(HasTraits):
  p = Array
  n = Range(0, 9, 5)
  #p is a 4 dimensional Array p[10][20][20][20]
  scene = Instance(MlabSceneModel, ())
  plot = Instance(PipelineBase)

  @on_trait_change('n,scene.activated')
  def update_plot(self):
     self.src = mlab.pipeline.scalar_field(self.p[self.n])
     if self.plot is None:                 
        self.plot = self.scene.mlab.pipeline.image_plane_widget(self.src,
                        plane_orientation='z_axes',
                        slice_index=10,
                        vmin=0, vmax=120)
     else:
        '''here should be the update function, i tried using mlab_source.set(self.src=self.src)
        and all variations of expressions in the brackets but nothing worked.
        I also searched for functions in IPW itself but didn't find something that could help me.'''

  #The layout of the dialog created
  view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                 height=400, width=400, show_label=False),
            Group('_', 'n'),
            resizable=True,
            )

my_model = Modell(p=p)
my_model.configure_traits()

我尝试更新管道并使用 self.plot.update_pipeline() 和 self.plot.update_data() 更新数据,但这也不起作用。

【问题讨论】:

    标签: python data-visualization mayavi


    【解决方案1】:

    好的,我找到了解决问题的方法,诀窍是直接通过管道更改数据。因此,在我的代码中,我只需将以下命令设置到 else 段中:

    self.plot.parent.parent.scalar_data = self.p[self.n]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 2016-10-04
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 2016-12-06
      相关资源
      最近更新 更多