本文整理汇总了Python中silx.gui.plot.PlotWindow.addCurve方法的典型用法代码示例。如果您正苦于以下问题:Python PlotWindow.addCurve方法的具体用法?Python PlotWindow.addCurve怎么用?Python PlotWindow.addCurve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类silx.gui.plot.PlotWindow
的用法示例。
在下文中一共展示了PlotWindow.addCurve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCurvesROIWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [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
示例2: SimpleFitGui
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [as 别名]
#.........这里部分代码省略.........
fname = self.fitModule.getFitFunction()
if fname in [None, "None", "NONE"]:
idx = 0
else:
idx = newConfig['fit']['functions'].index(fname) + 1
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)
示例3: TestCurvesROIWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [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')
#.........这里部分代码省略.........
示例4: PlotWindow
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [as 别名]
# creating QApplication is mandatory in order to use qt widget
app = qt.QApplication([])
sys.excepthook = qt.exceptionHandler
# create a PlotWindow
plotwin = PlotWindow()
# Add a new toolbar
toolbar = qt.QToolBar("My toolbar")
plotwin.addToolBar(toolbar)
# Get a reference to the PlotWindow's menu bar, add a menu
menubar = plotwin.menuBar()
actions_menu = menubar.addMenu("Custom actions")
# Initialize our action, give it plotwin as a parameter
myaction = ShiftUpAction(plotwin)
# Add action to the menubar and toolbar
toolbar.addAction(myaction)
actions_menu.addAction(myaction)
# Plot a couple of curves with synthetic data
x = [0, 1, 2, 3, 4, 5, 6]
y1 = [0, 1, 0, 1, 0, 1, 0]
y2 = [0, 1, 2, 3, 4, 5, 6]
plotwin.addCurve(x, y1, legend="triangle shaped curve")
plotwin.addCurve(x, y2, legend="oblique line")
plotwin.show()
app.exec_()
示例5: QXTube
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [as 别名]
class QXTube(qt.QWidget):
sigQXTubeSignal = qt.pyqtSignal(object)
def __init__(self, parent=None, initdict = None):
qt.QWidget.__init__(self, parent)
self.l = qt.QVBoxLayout(self)
self.l.setContentsMargins(0, 0, 0, 0)
self.l.setSpacing(0)
self.tubeWidget = TubeWidget(self, initdict = initdict)
self.setParameters = self.tubeWidget.setParameters
self.getParameters = self.tubeWidget.getParameters
label = qt.QLabel(self)
hbox = qt.QWidget(self)
hboxl = qt.QHBoxLayout(hbox)
hboxl.setContentsMargins(0, 0, 0, 0)
hboxl.setSpacing(0)
self.plotButton = qt.QPushButton(hbox)
self.plotButton.setText("Plot Continuum")
self.exportButton = qt.QPushButton(hbox)
self.exportButton.setText("Export to Fit")
#grid.addWidget(self.plotButton, 7, 1)
#grid.addWidget(self.exportButton, 7, 3)
hboxl.addWidget(self.plotButton)
hboxl.addWidget(self.exportButton)
self.l.addWidget(self.tubeWidget)
f = label.font()
f.setItalic(1)
label.setFont(f)
label.setAlignment(qt.Qt.AlignRight)
label.setText("H. Ebel, X-Ray Spectrometry 28 (1999) 255-266 ")
self.l.addWidget(label)
self.l.addWidget(hbox)
self.graph = PlotWindow(self, colormap=False, yInverted=False,
aspectRatio=False, control=False,
position=False, roi=False, mask=False,
fit=False)
self.pluginsToolButton = PluginsToolButton(plot=self.graph)
self.graph.toolBar().addWidget(self.pluginsToolButton)
self.graph.getInteractiveModeToolBar().getZoomModeAction().setVisible(False)
self.graph.getInteractiveModeToolBar().getPanModeAction().setVisible(False)
self.l.addWidget(self.graph)
self.graph.setGraphXLabel("Energy (keV)")
self.graph.setGraphYLabel("photons/sr/mA/keV/s")
self.plotButton.clicked.connect(self.plot)
self.exportButton.clicked.connect(self._export)
def plot(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)
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,
#.........这里部分代码省略.........
示例6: FftAction
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [as 别名]
toolbar = qt.QToolBar("My toolbar")
plotwin.addToolBar(toolbar)
myaction = FftAction(plotwin)
toolbar.addAction(myaction)
# x range: 0 -- 10 (1000 points)
x = numpy.arange(1000) * 0.01
twopi = 2 * numpy.pi
# Sum of sine functions with frequencies 3, 20 and 42 Hz
y1 = numpy.sin(twopi * 3 * x) + 1.5 * numpy.sin(twopi * 20 * x) + 2 * numpy.sin(twopi * 42 * x)
# Cosine with frequency 7 Hz and phase pi / 3
y2 = numpy.cos(twopi * 7 * (x - numpy.pi / 3))
# 5 periods of square wave, amplitude 2
y3 = numpy.zeros_like(x)
for i in [0, 2, 4, 6, 8]:
y3[i * len(x) // 10:(i + 1) * len(x) // 10] = 2
plotwin.addCurve(x, y1, legend="sin")
plotwin.addCurve(x, y2, legend="cos")
plotwin.addCurve(x, y3, legend="square wave")
plotwin.setGraphTitle("Original data")
plotwin.getYAxis().setLabel("amplitude")
plotwin.getXAxis().setLabel("time")
plotwin.show()
app.exec_()
sys.excepthook = sys.__excepthook__
示例7: TestCurveLegendsWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [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)
示例8: StripBackgroundWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import addCurve [as 别名]
class StripBackgroundWidget(qt.QWidget):
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.setWindowTitle("Strip and SNIP Configuration Window")
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
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,
#.........这里部分代码省略.........