Python Mayavi多场景选择器

Python Mayavi多场景选择器,python,user-interface,visualization,mayavi,mayavi.mlab,Python,User Interface,Visualization,Mayavi,Mayavi.mlab,我需要加载多个具有切换选项的场景。在图像上类似于: 对于按钮“1”,类似于mlab.points3d(x1、y1、z1、s1,颜色=蓝色) 对于按钮“2”,类似于mlab.points3d(x2、y2、z2、s2,颜色=红色) 对于按钮“3”,类似于mlab.points3d(x3,y3,z3,s3,color=green) 如何在另一个场景中管理图形?(我认为mlab.points3d应该在选择在场景之间切换之前完成)。 以及如何定义用于方案切换的按钮?下面是一个如何在pyqt中嵌入带有多个

我需要加载多个具有切换选项的场景。在图像上类似于:

对于按钮“1”,类似于
mlab.points3d(x1、y1、z1、s1,颜色=蓝色)

对于按钮“2”,类似于
mlab.points3d(x2、y2、z2、s2,颜色=红色)

对于按钮“3”,类似于
mlab.points3d(x3,y3,z3,s3,color=green)

如何在另一个场景中管理图形?(我认为
mlab.points3d
应该在选择在场景之间切换之前完成)。
以及如何定义用于方案切换的按钮?

下面是一个如何在pyqt中嵌入带有多个按钮的mayavi绘图的示例。这是基于来自mayavi网站的信息。如果您想编写一个相对较大的应用程序,我建议您将现在位于Ifmain==“main”行底部的代码移动到几个单独的类中

from pyface.qt import QtGui, QtCore
from traits.api import HasTraits, Instance, on_trait_change
from traitsui.api import View, Item
from mayavi.core.ui.api import MayaviScene, MlabSceneModel, \
        SceneEditor


################################################################################
#The actual visualization
class Visualization(HasTraits):
    scene = Instance(MlabSceneModel, ())


    @on_trait_change('scene.activated')
    def update_plot(self):
        # This function is called when the view is opened. We don't
        # populate the scene when the view is not yet open, as some
        # VTK features require a GLContext.

        # We can do normal mlab calls on the embedded scene.
        self.scene.mlab.clf()
        self.scene.mlab.test_points3d()

    def second_plot(self):
        self.scene.mlab.clf()

        from numpy import sin, cos, mgrid, pi, sqrt
        u, v = mgrid[- 0.035:pi:0.01, - 0.035:pi:0.01]

        X = 2 / 3. * (cos(u) * cos(2 * v)
                + sqrt(2) * sin(u) * cos(v)) * cos(u) / (sqrt(2) -
                                                         sin(2 * u) * sin(3 * v))
        Y = 2 / 3. * (cos(u) * sin(2 * v) -
                sqrt(2) * sin(u) * sin(v)) * cos(u) / (sqrt(2)
                - sin(2 * u) * sin(3 * v))
        Z = -sqrt(2) * cos(u) * cos(u) / (sqrt(2) - sin(2 * u) * sin(3 * v))
        S = sin(u)

        self.scene.mlab.mesh(X, Y, Z, scalars=S, colormap='YlGnBu', )

    def third_plot(self):
        self.scene.mlab.clf()
        self.scene.mlab.test_plot3d()

    # the layout of the dialog screated
    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=250, width=300, show_label=False),
                resizable=True # We need this to resize with the parent widget
                )


################################################################################
# The QWidget containing the visualization, this is pure PyQt4 code.
class MayaviQWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        layout = QtGui.QVBoxLayout(self)
        layout.setContentsMargins(0,0,0,0)
        layout.setSpacing(0)
        self.visualization = Visualization()

        # The edit_traits call will generate the widget to embed.
        self.ui = self.visualization.edit_traits(parent=self,
                                                 kind='subpanel').control
        layout.addWidget(self.ui)
        self.ui.setParent(self)


if __name__ == "__main__":
    # Don't create a new QApplication, it would unhook the Events
    # set by Traits on the existing QApplication. Simply use the
    # '.instance()' method to retrieve the existing one.
    app = QtGui.QApplication.instance()
    container = QtGui.QWidget()

    mayavi_widget = MayaviQWidget(container)

    container.setWindowTitle("Embedding Mayavi in a PyQt4 Application")
    # define a "complex" layout to test the behaviour
    layout = QtGui.QHBoxLayout(container)

    button_container = QtGui.QWidget()
    button_layout =  QtGui.QVBoxLayout(button_container)

    button1 = QtGui.QPushButton('1')
    button1.clicked.connect(mayavi_widget.visualization.update_plot)
    button_layout.addWidget(button1)

    button2 = QtGui.QPushButton('2')
    button2.clicked.connect(mayavi_widget.visualization.second_plot)
    button_layout.addWidget(button2)

    button3 = QtGui.QPushButton('3')
    button3.clicked.connect(mayavi_widget.visualization.third_plot)
    button_layout.addWidget(button3)

    layout.addWidget(button_container)
    button_container.show()

    layout.addWidget(mayavi_widget)
    container.show()
    window = QtGui.QMainWindow()
    window.setCentralWidget(container)
    window.show()

    # Start the main event loop.
    app.exec_()

你想用PyQt或纯mayavi代码构建GUI应用程序吗?@Jannick我认为PyQt可能更适合GUI部分-它似乎有更多的文档和示例。是的,这就是我想要的。现在是研究这段代码的时候了。