當前位置: 首頁>>代碼示例>>Python>>正文


Python PlotWindow.addImage方法代碼示例

本文整理匯總了Python中silx.gui.plot.PlotWindow.addImage方法的典型用法代碼示例。如果您正苦於以下問題:Python PlotWindow.addImage方法的具體用法?Python PlotWindow.addImage怎麽用?Python PlotWindow.addImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在silx.gui.plot.PlotWindow的用法示例。


在下文中一共展示了PlotWindow.addImage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestMaskToolsWidget

# 需要導入模塊: from silx.gui.plot import PlotWindow [as 別名]
# 或者: from silx.gui.plot.PlotWindow import addImage [as 別名]
class TestMaskToolsWidget(TestCaseQt):
    """Basic test for MaskToolsWidget"""

    def setUp(self):
        super(TestMaskToolsWidget, self).setUp()
        self.plot = PlotWindow()

        self.widget = MaskToolsWidget.MaskToolsDockWidget(self.plot, 'TEST')
        self.plot.addDockWidget(qt.Qt.BottomDockWidgetArea, self.widget)

        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.maskWidget = self.widget.widget()

    def tearDown(self):
        del self.maskWidget
        del self.widget

        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        del self.plot

        super(TestMaskToolsWidget, self).tearDown()

    def testEmptyPlot(self):
        """Empty plot, display MaskToolsDockWidget, toggle multiple masks"""
        self.maskWidget.setMultipleMasks('single')
        self.qapp.processEvents()

        self.maskWidget.setMultipleMasks('exclusive')
        self.qapp.processEvents()

    def _drag(self):
        """Drag from plot center to offset position"""
        plot = self.plot.centralWidget()
        xCenter, yCenter = plot.width() // 2, plot.height() // 2
        offset = min(plot.width(), plot.height()) // 10

        pos0 = xCenter, yCenter
        pos1 = xCenter + offset, yCenter + offset

        self.mouseMove(plot, pos=pos0)
        self.mousePress(plot, qt.Qt.LeftButton, pos=pos0)
        self.mouseMove(plot, pos=pos1)
        self.mouseRelease(plot, qt.Qt.LeftButton, pos=pos1)

    def _drawPolygon(self):
        """Draw a star polygon in the plot"""
        plot = self.plot.centralWidget()
        x, y = plot.width() // 2, plot.height() // 2
        offset = min(plot.width(), plot.height()) // 10

        star = [(x, y + offset),
                (x - offset, y - offset),
                (x + offset, y),
                (x - offset, y),
                (x + offset, y - offset)]

        for pos in star:
            self.mouseMove(plot, pos=pos)
            btn = qt.Qt.LeftButton if pos != star[-1] else qt.Qt.RightButton
            self.mouseClick(plot, btn, pos=pos)

    def _drawPencil(self):
        """Draw a star polygon in the plot"""
        plot = self.plot.centralWidget()
        x, y = plot.width() // 2, plot.height() // 2
        offset = min(plot.width(), plot.height()) // 10

        star = [(x, y + offset),
                (x - offset, y - offset),
                (x + offset, y),
                (x - offset, y),
                (x + offset, y - offset)]

        self.mouseMove(plot, pos=star[0])
        self.mousePress(plot, qt.Qt.LeftButton, pos=star[0])
        for pos in star:
            self.mouseMove(plot, pos=pos)
        self.mouseRelease(
            plot, qt.Qt.LeftButton, pos=star[-1])

    def testWithAnImage(self):
        """Plot with an image: test MaskToolsWidget interactions"""

        # Add and remove a image (this should enable/disable GUI + change mask)
        self.plot.addImage(numpy.random.random(1024**2).reshape(1024, 1024),
                           legend='test')
        self.qapp.processEvents()

        self.plot.remove('test', kind='image')
        self.qapp.processEvents()

        self.plot.addImage(numpy.arange(1024**2).reshape(1024, 1024),
                           legend='test')
        self.qapp.processEvents()

        # Test draw rectangle #
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
#.........這裏部分代碼省略.........
開發者ID:PiRK,項目名稱:silx,代碼行數:103,代碼來源:testMaskToolsWidget.py

示例2: TestProfileToolBar

# 需要導入模塊: from silx.gui.plot import PlotWindow [as 別名]
# 或者: from silx.gui.plot.PlotWindow import addImage [as 別名]
class TestProfileToolBar(TestCaseQt, ParametricTestCase):
    """Tests for ProfileToolBar widget."""

    def setUp(self):
        super(TestProfileToolBar, self).setUp()
        profileWindow = PlotWindow()
        self.plot = PlotWindow()
        self.toolBar = Profile.ProfileToolBar(
            plot=self.plot, profileWindow=profileWindow)
        self.plot.addToolBar(self.toolBar)

        self.plot.show()
        self.qWaitForWindowExposed(self.plot)
        profileWindow.show()
        self.qWaitForWindowExposed(profileWindow)

        self.mouseMove(self.plot)  # Move to center
        self.qapp.processEvents()

    def tearDown(self):
        self.qapp.processEvents()
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        del self.plot
        del self.toolBar

        super(TestProfileToolBar, self).tearDown()

    def testAlignedProfile(self):
        """Test horizontal and vertical profile, without and with image"""
        # Use Plot backend widget to submit mouse events
        widget = self.plot.getWidgetHandle()
        for method in ('sum', 'mean'):
            with self.subTest(method=method):
                # 2 positions to use for mouse events
                pos1 = widget.width() * 0.4, widget.height() * 0.4
                pos2 = widget.width() * 0.6, widget.height() * 0.6

                for action in (self.toolBar.hLineAction, self.toolBar.vLineAction):
                    with self.subTest(mode=action.text()):
                        # Trigger tool button for mode
                        toolButton = getQToolButtonFromAction(action)
                        self.assertIsNot(toolButton, None)
                        self.mouseMove(toolButton)
                        self.mouseClick(toolButton, qt.Qt.LeftButton)

                        # Without image
                        self.mouseMove(widget, pos=pos1)
                        self.mouseClick(widget, qt.Qt.LeftButton, pos=pos1)

                        # with image
                        self.plot.addImage(
                            numpy.arange(100 * 100).reshape(100, -1))
                        self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
                        self.mouseMove(widget, pos=pos2)
                        self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)

                        self.mouseMove(widget)
                        self.mouseClick(widget, qt.Qt.LeftButton)

    def testDiagonalProfile(self):
        """Test diagonal profile, without and with image"""
        # Use Plot backend widget to submit mouse events
        widget = self.plot.getWidgetHandle()

        for method in ('sum', 'mean'):
            with self.subTest(method=method):
                self.toolBar.setProfileMethod(method)

                # 2 positions to use for mouse events
                pos1 = widget.width() * 0.4, widget.height() * 0.4
                pos2 = widget.width() * 0.6, widget.height() * 0.6

                for image in (False, True):
                    with self.subTest(image=image):
                        if image:
                            self.plot.addImage(
                                numpy.arange(100 * 100).reshape(100, -1))

                        # Trigger tool button for diagonal profile mode
                        toolButton = getQToolButtonFromAction(
                            self.toolBar.lineAction)
                        self.assertIsNot(toolButton, None)
                        self.mouseMove(toolButton)
                        self.mouseClick(toolButton, qt.Qt.LeftButton)
                        self.toolBar.lineWidthSpinBox.setValue(3)

                        # draw profile line
                        self.mouseMove(widget, pos=pos1)
                        self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
                        self.mouseMove(widget, pos=pos2)
                        self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)

                        if image is True:
                            profileCurve = self.toolBar.getProfilePlot().getAllCurves()[0]
                            if method == 'sum':
                                self.assertTrue(profileCurve.getData()[1].max() > 10000)
                            elif method == 'mean':
                                self.assertTrue(profileCurve.getData()[1].max() < 10000)
                        self.plot.clear()
開發者ID:dnaudet,項目名稱:silx,代碼行數:102,代碼來源:testProfile.py


注:本文中的silx.gui.plot.PlotWindow.addImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。