def do_update(self, data, roi=False): popt, perr, counts = data[int(roi) * 3:int(roi) * 3 + 3] avg, contrast, freq, phase = popt davg, dcontrast, dfreq, dphase = perr # data contains a list [avg, avgErr, contrast, contrastErr, # freq, freErr, phase, phaseErr, 16 * counts] self.avg_value.setText('%.0f' % abs(avg)) self.avg_error.setText('%.1f' % davg) self.contrast_value.setText('%.2f' % abs(contrast)) self.contrast_error.setText('%.3f' % dcontrast) self.freq_value.setText('%.2f' % freq) self.freq_error.setText('%.3f' % dfreq) self.phase_value.setText('%.2f' % (phase + np.pi if contrast < 0 else phase)) self.phase_error.setText('%.3f' % dphase) # now update plot datacurve, fitcurve = self.plotwidget._curves fitcurve.x = np.arange(-0.5, 16.5, 0.1) fitcurve.y = np.array([ self.model_sine(x, avg, contrast, freq, phase) for x in fitcurve.x ]) datacurve.x = np.arange(0, 16, 1) datacurve.y = np.array(counts) datacurve.errorBar1 = ErrorBar(datacurve.x, datacurve.y, np.sqrt(datacurve.y), markercolor=datacurve.markercolor) self.plotwidget.reset() self.plotwidget.update()
def setCurveData(self, curve, plotcurve): xname = curve.default_xname \ if self.current_xname == 'Default' else self.current_xname if self.normalized == 'Maximum': norm = [max(curve.datay)] * len(curve.datay) else: norm = curve.datanorm[self.normalized] if self.normalized else None try: x, y, dy = prepareData(curve.datax[xname], curve.datay, curve.datady, norm) except ValueError: # empty column, should be ignored x, y, dy = np.array([0]), np.array([0]), None y = numpy.ma.masked_equal(y, 0) if dy is not None: errbar = ErrorBar(x, y, dy, markercolor=plotcurve.markercolor) plotcurve.errorBar1 = errbar plotcurve.x = x plotcurve.y = y plotcurve.filly = 0.1 if self.isLogScaling() else 0 plotcurve.visible = not (curve.disabled or curve.hidden or not x.size) plotcurve.legend = curve.full_description if not curve.hidden else ''
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)), "qtgrdemo.ui"), self) dictPrintType = dict(gr.PRINT_TYPE) map(dictPrintType.pop, [gr.PRINT_JPEG, gr.PRINT_TIF]) self._saveTypes = (";;".join(dictPrintType.values()) + ";;" + ";;".join(gr.GRAPHIC_TYPE.values())) self._saveName = None self._title = unicode(self.windowTitle()) self._startupTime = time.time() self._chkLogX.stateChanged.connect(self._logXClicked) self._chkLogY.stateChanged.connect(self._logYClicked) self._chkGrid.stateChanged.connect(self._gridClicked) self._chkErr.stateChanged.connect(self._errorsClicked) self._chkKeepRatio.stateChanged.connect(self._keepRatioClicked) self._btnReset.clicked.connect(self._resetClicked) self._btnPick.clicked.connect(self._pickClicked) self._shell.returnPressed.connect(self._shellEx) self._actionSave.triggered.connect(self.save) self._actionPrint.triggered.connect(self.printGR) self._gr.logXinDomain.connect(self._logXinDomain) self._gr.logYinDomain.connect(self._logYinDomain) self._gr.modePick.connect(self._pickModeChanged) guiConn = GUIConnector(self._gr) guiConn.connect(MouseEvent.MOUSE_MOVE, self.mouseMoveGr) guiConn.connect(PickEvent.PICK_PRESS, self.pointPickGr) guiConn.connect(LegendEvent.ROI_CLICKED, self.legendClick) guiConn.connect(LegendEvent.ROI_OVER, self.legendOver) x = [-3.3 + t * .1 for t in range(66)] y = [t ** 5 - 13 * t ** 3 + 36 * t for t in x] x2 = [-3.5 + i * .5 for i in range(0, 15)] y2 = x2 dneg = map(lambda y: y - 0.25 * abs(y), y) dpos = map(lambda y: y + 0.25 * abs(y), y) self._errBar = ErrorBar(x, y, dneg, dpos) self._curveFoo = PlotCurve(x, y, legend="foo bar") axes = PlotAxes().addCurves(self._curveFoo) axes.setXtickCallback(self._xtickCallBack) self._plot = Plot((.1, .92, .2, .88)).addAxes(axes, PlotAxes(drawX=False).plot(x2, y2)) self._plot.offsetXLabel = -.1 self._plot2 = Plot((.1, .95, .15, .88)).addAxes(PlotAxes().addCurves(PlotCurve(x2, y2, legend="second"))) self._plot.title = "QtGR Demo" self._plot.subTitle = "Multiple Axes Example" self._plot.xlabel = "x" self._plot.ylabel = "f(x)" self._plot.setLegend(True) self._gr.addPlot(self._plot) self._plot2.title = "Second Widget" self._plot2.subTitle = "Linear Example (less interactive)" self._plot2.xlabel = "x2" self._plot2.ylabel = "f2(x2)" self._plot2.setLegend(True) self._plot2.setGrid(False) self._gr2.addPlot(self._plot2)