当前位置: 首页>>代码示例>>Python>>正文


Python PlotWindow.setActiveCurve方法代码示例

本文整理汇总了Python中silx.gui.plot.PlotWindow.setActiveCurve方法的典型用法代码示例。如果您正苦于以下问题:Python PlotWindow.setActiveCurve方法的具体用法?Python PlotWindow.setActiveCurve怎么用?Python PlotWindow.setActiveCurve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在silx.gui.plot.PlotWindow的用法示例。


在下文中一共展示了PlotWindow.setActiveCurve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCurvesROIWidget

# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import setActiveCurve [as 别名]
class TestCurvesROIWidget(TestCaseQt):
    """Basic test for CurvesROIWidget"""

    def setUp(self):
        super(TestCurvesROIWidget, self).setUp()
        self.plot = PlotWindow()
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.widget = CurvesROIWidget.CurvesROIDockWidget(plot=self.plot, name='TEST')
        self.widget.show()
        self.qWaitForWindowExposed(self.widget)

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

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

        super(TestCurvesROIWidget, self).tearDown()

    def testEmptyPlot(self):
        """Empty plot, display ROI widget"""
        pass

    def testWithCurves(self):
        """Plot with curves: test all ROI widget buttons"""
        for offset in range(2):
            self.plot.addCurve(numpy.arange(1000),
                               offset + numpy.random.random(1000),
                               legend=str(offset))

        # Add two ROI
        self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
        self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)

        # Change active curve
        self.plot.setActiveCurve(str(1))

        # Delete a ROI
        self.mouseClick(self.widget.roiWidget.delButton, qt.Qt.LeftButton)

        with temp_dir() as tmpDir:
            self.tmpFile = os.path.join(tmpDir, 'test.ini')

            # Save ROIs
            self.widget.roiWidget.save(self.tmpFile)
            self.assertTrue(os.path.isfile(self.tmpFile))

            # Reset ROIs
            self.mouseClick(self.widget.roiWidget.resetButton,
                            qt.Qt.LeftButton)

            # Load ROIs
            self.widget.roiWidget.load(self.tmpFile)

            del self.tmpFile
开发者ID:silx-kit,项目名称:silx,代码行数:62,代码来源:testCurvesROIWidget.py

示例2: SimpleFitGui

# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import setActiveCurve [as 别名]

#.........这里部分代码省略.........
        self.topWidget.fitFunctionCombo.setCurrentIndex(idx)
        fname = self.fitModule.getBackgroundFunction()
        if fname in [None, "None", "NONE"]:
            idx = 0
        else:
            idx = newConfig['fit']['functions'].index(fname) + 1
        idx = self.topWidget.backgroundCombo.findText(fname)
        self.topWidget.backgroundCombo.setCurrentIndex(idx)
        _logger.debug("TABLE TO BE CLEANED")
        #self.estimate()

    def setFitFunction(self, fname):
        current = self.fitModule.getFitFunction()
        if current != fname:
            self.fitModule.setFitFunction(fname)
            idx = self.topWidget.fitFunctionCombo.findText(fname)
            self.topWidget.fitFunctionCombo.setCurrentIndex(idx)

    def setBackgroundFunction(self, fname):
        current = self.fitModule.getBackgroundFunction()
        if current != fname:
            self.fitModule.setBackgroundFunction(fname)
            idx = self.topWidget.backgroundCombo.findText(fname)
            self.topWidget.backgroundCombo.setCurrentIndex(idx)

    def setData(self, *var, **kw):
        returnValue = self.fitModule.setData(*var, **kw)
        if self.__useTab:
            if hasattr(self.graph, "addCurve"):
                self.graph.clear()
                self.graph.addCurve(self.fitModule._x,
                                    self.fitModule._y,
                                    legend='Data')
                self.graph.setActiveCurve('Data')
            elif hasattr(self.graph, "newCurve"):
                # TODO: remove if not used
                self.graph.clearCurves()
                self.graph.newCurve('Data',
                                    self.fitModule._x,
                                    self.fitModule._y)
                self.graph.replot()
        return returnValue

    def estimate(self):
        self.setStatus("Estimate started")
        self.statusWidget.chi2Line.setText("")
        try:
            x = self.fitModule._x
            y = self.fitModule._y
            self.graph.clear()
            self.graph.addCurve(x, y, 'Data')
            self.graph.setActiveCurve('Data')
            self.fitModule.estimate()
            self.setStatus()
            self.parametersTable.fillTableFromFit(self.fitModule.paramlist)
        except:
            if _logger.getEffectiveLevel() == logging.DEBUG:
                raise
            text = "%s:%s" % (sys.exc_info()[0], sys.exc_info()[1])
            msg = qt.QMessageBox(self)
            msg.setIcon(qt.QMessageBox.Critical)
            msg.setText(text)
            msg.exec_()
            self.setStatus("Ready (after estimate error)")

    def setStatus(self, text=None):
开发者ID:maurov,项目名称:pymca,代码行数:70,代码来源:SimpleFitGui.py

示例3: TestCurvesROIWidget

# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import setActiveCurve [as 别名]
class TestCurvesROIWidget(TestCaseQt):
    """Basic test for CurvesROIWidget"""

    def setUp(self):
        super(TestCurvesROIWidget, self).setUp()
        self.plot = PlotWindow()
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        self.widget = self.plot.getCurvesRoiDockWidget()

        self.widget.show()
        self.qWaitForWindowExposed(self.widget)

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

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

        super(TestCurvesROIWidget, self).tearDown()

    def testWithCurves(self):
        """Plot with curves: test all ROI widget buttons"""
        for offset in range(2):
            self.plot.addCurve(numpy.arange(1000),
                               offset + numpy.random.random(1000),
                               legend=str(offset))

        # Add two ROI
        self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
        self.qWait(200)
        self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
        self.qWait(200)

        # Change active curve
        self.plot.setActiveCurve(str(1))

        # Delete a ROI
        self.mouseClick(self.widget.roiWidget.delButton, qt.Qt.LeftButton)
        self.qWait(200)

        with temp_dir() as tmpDir:
            self.tmpFile = os.path.join(tmpDir, 'test.ini')

            # Save ROIs
            self.widget.roiWidget.save(self.tmpFile)
            self.assertTrue(os.path.isfile(self.tmpFile))
            self.assertTrue(len(self.widget.getRois()) is 2)

            # Reset ROIs
            self.mouseClick(self.widget.roiWidget.resetButton,
                            qt.Qt.LeftButton)
            self.qWait(200)
            rois = self.widget.getRois()
            self.assertTrue(len(rois) is 1)
            print(rois)
            roiID = list(rois.keys())[0]
            self.assertTrue(rois[roiID].getName() == 'ICR')

            # Load ROIs
            self.widget.roiWidget.load(self.tmpFile)
            self.assertTrue(len(self.widget.getRois()) is 2)

            del self.tmpFile

    def testMiddleMarker(self):
        """Test with middle marker enabled"""
        self.widget.roiWidget.roiTable.setMiddleROIMarkerFlag(True)

        # Add a ROI
        self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)

        for roiID in self.widget.roiWidget.roiTable._markersHandler._roiMarkerHandlers:
            handler = self.widget.roiWidget.roiTable._markersHandler._roiMarkerHandlers[roiID]
            assert handler.getMarker('min')
            xleftMarker = handler.getMarker('min').getXPosition()
            xMiddleMarker = handler.getMarker('middle').getXPosition()
            xRightMarker = handler.getMarker('max').getXPosition()
            thValue = xleftMarker + (xRightMarker - xleftMarker) / 2.
            self.assertAlmostEqual(xMiddleMarker, thValue)

    def testAreaCalculation(self):
        """Test result of area calculation"""
        x = numpy.arange(100.)
        y = numpy.arange(100.)

        # Add two curves
        self.plot.addCurve(x, y, legend="positive")
        self.plot.addCurve(-x, y, legend="negative")

        # Make sure there is an active curve and it is the positive one
        self.plot.setActiveCurve("positive")

        # Add two ROIs
        roi_neg = CurvesROIWidget.ROI(name='negative', fromdata=-20,
                                      todata=-10, type_='X')
#.........这里部分代码省略.........
开发者ID:dnaudet,项目名称:silx,代码行数:103,代码来源:testCurvesROIWidget.py

示例4: QXTube

# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import setActiveCurve [as 别名]

#.........这里部分代码省略.........
        alphae          = d["alphae"]
        alphax          = d["alphax"]

        delta           = d["deltaplotting"]
        e = numpy.arange(1, voltage, delta)

        if __name__ == "__main__":
            continuumR = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=0,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)

            continuumT = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=1,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)

            self.graph.addCurve(e, continuumR, "continuumR")
            self.graph.addCurve(e, continuumT, "continuumT")
        else:
            continuum = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=transmission,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)
            self.graph.addCurve(e, continuum, "continuum")
            self.graph.setActiveCurve("continuum")

        self.graph.resetZoom()

    def _export(self):
        d = self.tubeWidget.getParameters()
        transmission    = d["transmission"]
        anode           = d["anode"]
        anodedensity    = d["anodedensity"]
        anodethickness  = d["anodethickness"]

        voltage         = d["voltage"]
        wele            = d["window"]
        wdensity        = d["windowdensity"]
        wthickness      = d["windowthickness"]
        fele            = d["filter1"]
        fdensity        = d["filter1density"]
        fthickness      = d["filter1thickness"]
        filterlist      =[[fele, fdensity, fthickness]]
        alphae          = d["alphae"]
        alphax          = d["alphax"]
        delta           = d["deltaplotting"]

        e = numpy.arange(1, voltage, delta)

        d["event"]      = "TubeUpdated"
        d["energyplot"] = e
        d["continuum"]  = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=transmission,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)


        fllines = XRayTubeEbel.characteristicEbel([anode, anodedensity, anodethickness],
                     voltage,
                     [wele, wdensity, wthickness],
                     alphae=alphae, alphax=alphax,
                     transmission=transmission,
                     targetthickness=anodethickness,
                     filterlist=filterlist)

        d["characteristic"] = fllines
        fsum = 0.0
        for l in fllines:
            _logger.debug("%s %.4f %.3e", l[2], l[0], l[1])
            fsum += l[1]
        _logger.debug("%s", fsum)

        energy, energyweight, energyscatter = XRayTubeEbel.generateLists(
                                                        [anode, anodedensity, anodethickness],
                                                        voltage,
                                                        window=[wele, wdensity, wthickness],
                                                        alphae=alphae, alphax=alphax,
                                                        transmission=transmission,
                                                        targetthickness=anodethickness,
                                                        filterlist=filterlist)

        d["energylist"]  = energy
        d["weightlist"]  = energyweight
        d["scatterlist"] = energyscatter
        d["flaglist"]    = numpy.ones(len(energy))

        self.sigQXTubeSignal.emit(d)
开发者ID:maurov,项目名称:pymca,代码行数:104,代码来源:QXTube.py

示例5: TestCurveLegendsWidget

# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import setActiveCurve [as 别名]
class TestCurveLegendsWidget(TestCaseQt, ParametricTestCase):
    """Tests for CurveLegendsWidget class"""

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

        self.legends = CurveLegendsWidget.CurveLegendsWidget()
        self.legends.setPlotWidget(self.plot)

        dock = qt.QDockWidget()
        dock.setWindowTitle('Curve Legends')
        dock.setWidget(self.legends)
        self.plot.addTabbedDockWidget(dock)

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

    def tearDown(self):
        del self.legends
        self.qapp.processEvents()
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        del self.plot
        super(TestCurveLegendsWidget, self).tearDown()

    def _assertNbLegends(self, count):
        """Check the number of legends in the CurveLegendsWidget"""
        children = self.legends.findChildren(CurveLegendsWidget._LegendWidget)
        self.assertEqual(len(children), count)

    def testAddRemoveCurves(self):
        """Test CurveLegendsWidget while adding/removing curves"""
        self.plot.addCurve((0, 1), (1, 2), legend='a')
        self._assertNbLegends(1)
        self.plot.addCurve((0, 1), (2, 3), legend='b')
        self._assertNbLegends(2)

        # Detached/attach
        self.legends.setPlotWidget(None)
        self._assertNbLegends(0)

        self.legends.setPlotWidget(self.plot)
        self._assertNbLegends(2)

        self.plot.clear()
        self._assertNbLegends(0)

    def testUpdateCurves(self):
        """Test CurveLegendsWidget while updating curves """
        self.plot.addCurve((0, 1), (1, 2), legend='a')
        self._assertNbLegends(1)
        self.plot.addCurve((0, 1), (2, 3), legend='b')
        self._assertNbLegends(2)

        # Activate curve
        self.plot.setActiveCurve('a')
        self.qapp.processEvents()
        self.plot.setActiveCurve('b')
        self.qapp.processEvents()

        # Change curve style
        curve = self.plot.getCurve('a')
        curve.setLineWidth(2)
        for linestyle in (':', '', '--', '-'):
            with self.subTest(linestyle=linestyle):
                curve.setLineStyle(linestyle)
                self.qapp.processEvents()
                self.qWait(1000)

        for symbol in ('o', 'd', '', 's'):
            with self.subTest(symbol=symbol):
                curve.setSymbol(symbol)
                self.qapp.processEvents()
                self.qWait(1000)
开发者ID:dnaudet,项目名称:silx,代码行数:77,代码来源:testCurveLegendsWidget.py

示例6: StripBackgroundWidget

# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import setActiveCurve [as 别名]

#.........这里部分代码省略.........
        self.mainLayout.setSpacing(2)
        self.parametersWidget = StripParametersWidget(self)
        self.graphWidget = PlotWindow(self, position=False, aspectRatio=False,
                                      colormap=False, yInverted=False,
                                      roi=False, mask=False, fit=False)
        toolBar = self.graphWidget.getInteractiveModeToolBar()
        toolBar.getZoomModeAction().setVisible(False)
        toolBar.getPanModeAction().setVisible(False)

        self.mainLayout.addWidget(self.parametersWidget)
        self.mainLayout.addWidget(self.graphWidget)
        self.getParameters = self.parametersWidget.getParameters
        self.setParameters = self.parametersWidget.setParameters
        self._x = None
        self._y = None
        self.parametersWidget.sigStripParametersWidgetSignal.connect( \
                     self._slot)

    def setData(self, x, y):
        self._x = x
        self._y = y
        self.update()
        self.graphWidget.resetZoom()

    def _slot(self, ddict):
        self.update()

    def update(self):
        if self._y is None:
            return

        pars = self.getParameters()

        #smoothed data
        y = numpy.ravel(numpy.array(self._y)).astype(numpy.float)
        ysmooth = SpecfitFuns.SavitskyGolay(y, pars['stripfilterwidth'])
        f=[0.25,0.5,0.25]
        ysmooth[1:-1] = numpy.convolve(ysmooth,f,mode=0)
        ysmooth[0] = 0.5 *(ysmooth[0] + ysmooth[1])
        ysmooth[-1] = 0.5 * (ysmooth[-1] + ysmooth[-2])

        #loop for anchors
        x = self._x
        niter = pars['stripiterations']
        anchorslist = []
        if pars['stripanchorsflag']:
            if pars['stripanchorslist'] is not None:
                ravelled = x
                for channel in pars['stripanchorslist']:
                    if channel <= ravelled[0]:continue
                    index = numpy.nonzero(ravelled >= channel)[0]
                    if len(index):
                        index = min(index)
                        if index > 0:
                            anchorslist.append(index)
        if niter > 1000:
            stripBackground = SpecfitFuns.subac(ysmooth,
                                            pars['stripconstant'],
                                            niter,
                                            pars['stripwidth'],
                                            anchorslist)
            #final smoothing
            stripBackground = SpecfitFuns.subac(stripBackground,
                                  pars['stripconstant'],
                                  500,1,
                                  anchorslist)
        elif niter > 0:
            stripBackground = SpecfitFuns.subac(ysmooth,
                                            pars['stripconstant'],
                                            niter,
                                            pars['stripwidth'],
                                            anchorslist)
        else:
            stripBackground = 0.0 * ysmooth + ysmooth.min()

        if len(anchorslist) == 0:
            anchorslist = [0, len(ysmooth)-1]
        anchorslist.sort()
        snipBackground = 0.0 * ysmooth
        lastAnchor = 0
        width = pars['snipwidth']
        for anchor in anchorslist:
            if (anchor > lastAnchor) and (anchor < len(ysmooth)):
                snipBackground[lastAnchor:anchor] =\
                            SpecfitFuns.snip1d(ysmooth[lastAnchor:anchor], width, 0)
                lastAnchor = anchor
        if lastAnchor < len(ysmooth):
            snipBackground[lastAnchor:] =\
                            SpecfitFuns.snip1d(ysmooth[lastAnchor:], width, 0)

        self.graphWidget.addCurve(x, y,
                                  legend='Input Data',
                                  resetzoom=False)
        self.graphWidget.addCurve(x, stripBackground,
                                  resetzoom=False,
                                  legend='Strip Background')
        self.graphWidget.addCurve(x, snipBackground,
                                  resetzoom=False,
                                  legend='SNIP Background')
        self.graphWidget.setActiveCurve('Input Data')
开发者ID:maurov,项目名称:pymca,代码行数:104,代码来源:StripBackgroundWidget.py


注:本文中的silx.gui.plot.PlotWindow.setActiveCurve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。