def __init__(self, parent=None): Plot1D.__init__(self, parent) self._plotType = "SCAN" # needed by legacy plugins self._toolbar = qt.QToolBar(self) self.addToolBar(self._toolbar) pluginsToolButton = PluginsToolButton(plot=self, parent=self) if PLUGINS_DIR: pluginsToolButton.getPlugins( method="getPlugin1DInstance", directoryList=PLUGINS_DIR) self._toolbar.addWidget(pluginsToolButton)
def __init__(self, parent=None): """ :param parent: Parent QWidget """ super(ArrayCurvePlot, self).__init__(parent) self.__signals = None self.__signals_names = None self.__signal_errors = None self.__axis = None self.__axis_name = None self.__x_axis_errors = None self.__values = None self._plot = Plot1D(self) self._selector = NumpyAxesSelector(self) self._selector.setNamedAxesSelectorVisibility(False) self.__selector_is_connected = False self._plot.sigActiveCurveChanged.connect( self._setYLabelFromActiveLegend) layout = qt.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._plot) layout.addWidget(self._selector) self.setLayout(layout)
def get_plot_mean_baseline(backend): plot = Plot1D(backend=backend) x = numpy.arange(0, 10, step=0.1) y = numpy.sin(x) plot.addCurve(x=x, y=y, baseline=0, fill=True) plot.setYAxisLogarithmic(True) return plot
def setUp(self): TestCaseQt.setUp(self) self.plot = Plot1D() self.plot.show() x = range(20) y = range(20) self.plot.addCurve(x, y, legend='curve0') y = range(12, 32) self.plot.addCurve(x, y, legend='curve1') y = range(-2, 18) self.plot.addCurve(x, y, legend='curve2') self.widget = StatsWidget.StatsWidget(plot=self.plot) self.statsTable = self.widget._statsTable mystats = statshandler.StatsHandler( (stats.StatMin(), (stats.StatCoordMin(), statshandler.StatFormatter(None, qt.QTableWidgetItem)), stats.StatMax(), (stats.StatCoordMax(), statshandler.StatFormatter(None, qt.QTableWidgetItem)), stats.StatDelta(), ('std', numpy.std), ('mean', numpy.mean), stats.StatCOM())) self.statsTable.setStats(mystats)
def main(): app = qt.QApplication([]) plot = Plot1D() x = numpy.arange(21) y = numpy.arange(21) plot.addCurve(x=x, y=y, legend='myCurve') plot.addCurve(x=x, y=(y + 5), legend='myCurve2') plot.setActiveCurve('myCurve') plot.addScatter(x=[0, 2, 5, 5, 12, 20], y=[2, 3, 4, 20, 15, 6], value=[5, 6, 7, 10, 90, 20], legend='myScatter') stats = [ ('sum', numpy.sum), Integral(), (COM(), '{0:.2f}'), ] plot.getStatsWidget().setStats(stats) plot.getStatsWidget().parent().setVisible(True) plot.show() app.exec_()
def __init__(self, parent=None): """ :param parent: Parent QWidget """ super(ArrayCurvePlot, self).__init__(parent) self.__signals = None self.__signals_names = None self.__signal_errors = None self.__axis = None self.__axis_name = None self.__x_axis_errors = None self.__values = None self._plot = Plot1D(self) self.selectorDock = qt.QDockWidget("Data selector", self._plot) # not closable self.selectorDock.setFeatures(qt.QDockWidget.DockWidgetMovable | qt.QDockWidget.DockWidgetFloatable) self._selector = NumpyAxesSelector(self.selectorDock) self._selector.setNamedAxesSelectorVisibility(False) self.__selector_is_connected = False self.selectorDock.setWidget(self._selector) self._plot.addTabbedDockWidget(self.selectorDock) self._plot.sigActiveCurveChanged.connect( self._setYLabelFromActiveLegend) layout = qt.QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._plot, 0, 0) self.setLayout(layout)
def setUp(self): self.plot1d = Plot1D() x = range(20) y = range(20) self.plot1d.addCurve(x, y, legend='curve0') self.curveItem = self.plot1d.getCurve('curve0') self.stat = stats.StatMin()
def get_plot_log(backend): plot = Plot1D(backend=backend) x = numpy.arange(0, 10, step=0.01) y = numpy.exp2(x) baseline = numpy.exp(x) plot.addCurve(x=x, y=y, baseline=baseline, fill=True) plot.setYAxisLogarithmic(True) return plot
def __init__(self): super(QWidget, self).__init__() self.layout = QVBoxLayout(self) self.raw_data = None self.flatfield_image = None self.path = None self.diagram_data_array = [] self.angles = [] # Initialize tab screen self.tabs = QTabWidget() self.raw_data_tab = QWidget() # Create an unfolding data tab self.unfolded_data_tab = UnfoldingDataTab(self) self.diagram_tab = QWidget() self.fitting_data_tab = QWidget() # Create raw data display tab self.raw_data_tab.layout = QVBoxLayout(self.raw_data_tab) self.raw_data_viewer = RawDataViewer(self.raw_data_tab) # Create diagram plot data tab self.diagram_tab.layout = QVBoxLayout(self.diagram_tab) self.diagram_data_plot = Plot1D(self.diagram_tab) # Create fitting curve tab self.fitting_data_tab.layout = QVBoxLayout(self.fitting_data_tab) self.fitting_data_selector = NumpyAxesSelector(self.fitting_data_tab) self.fitting_data_plot = Plot1D(self.fitting_data_tab) self.fitting_widget = self.fitting_data_plot.getFitAction() self.fit_action = FitAction(plot=self.fitting_data_plot, parent=self.fitting_data_plot) self.toolbar = QToolBar("New") # Create automatic fitting tab self.automatic_fit_tab = FittingDataTab(self) self.unfolded_data_tab.viewer.get_unfold_with_flatfield_action( ).unfoldWithFlatfieldClicked.connect(self.get_calibration) self.unfolded_data_tab.viewer.get_unfold_action( ).unfoldClicked.connect(self.get_calibration) self.unfolded_data_tab.unfoldingFinished.connect( self.create_diagram_array) self.init_UI()
def testSetAnotherPlot(self): plot2 = Plot1D() plot2.addCurve(x=range(26), y=range(26), legend='new curve') self.widget.setPlot(plot2) self.assertTrue(self.widget.rowCount() is 1) self.qapp.processEvents() plot2.setAttribute(qt.Qt.WA_DeleteOnClose) plot2.close() plot2 = None
def createCurveContext(self): self.plot1d = Plot1D() x = range(20) y = range(20) self.plot1d.addCurve(x, y, legend='curve0') self.curveContext = stats._CurveContext( item=self.plot1d.getCurve('curve0'), plot=self.plot1d, onlimits=False)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.hist = Plot1D(self) self.stack = StackView(self) self.stack.setColormap({'name': 'viridis', 'autoscale': True}) self.setLayout(qt.QHBoxLayout()) splitter = qt.QSplitter() splitter.addWidget(self.hist) splitter.addWidget(self.stack) self.layout().addWidget(splitter)
def createHistogramContext(self): self.plotHisto = Plot1D() x = range(20) y = range(20) self.plotHisto.addHistogram(x, y, legend='histo0') self.histoContext = stats._HistogramContext( item=self.plotHisto.getHistogram('histo0'), plot=self.plotHisto, onlimits=False, roi=self._1Droi)
def main(argv=None): """Display few lines with markers. """ global app # QApplication must be global to avoid seg fault on quit app = qt.QApplication([]) sys.excepthook = qt.exceptionHandler mainWindow = Plot1D(backend="gl") mainWindow.setAttribute(qt.Qt.WA_DeleteOnClose) plot = mainWindow plot.setDataMargins(0.1, 0.1, 0.1, 0.1) plot.addCurve(x=[-10, 0, 0, -10, -10], y=[90, 90, 10, 10, 90], legend="box1", color="gray") plot.addCurve(x=[110, 100, 100, 110, 110], y=[90, 90, 10, 10, 90], legend="box2", color="gray") plot.addCurve(y=[-10, 0, 0, -10, -10], x=[90, 90, 10, 10, 90], legend="box3", color="gray") plot.addCurve(y=[110, 100, 100, 110, 110], x=[90, 90, 10, 10, 90], legend="box4", color="gray") def addLine(source, destination, symbolSource, symbolDestination, legend, color): line = numpy.array([source, destination]).T plot.addCurve(x=line[0, :], y=line[1, :], color=color, legend=legend) plot.addMarker(x=source[0], y=source[1], symbol=symbolSource, color=color) plot.addMarker(x=destination[0], y=destination[1], symbol=symbolDestination, color=color) addLine([0, 50], [100, 50], "caretleft", "caretright", "l1", "red") addLine([0, 30], [100, 30], "tickup", "tickdown", "l2", "blue") addLine([0, 70], [100, 70], "|", "|", "l3", "black") addLine([50, 0], [50, 100], "caretdown", "caretup", "l4", "red") addLine([30, 0], [30, 100], "tickleft", "tickright", "l5", "blue") addLine([70, 0], [70, 100], "_", "_", "l6", "black") mainWindow.setVisible(True) return app.exec()
def setUp(self): TestCaseQt.setUp(self) self.plot1d = Plot1D() x = range(20) y = range(20) self.plot1d.addCurve(x, y, legend='curve0') self.curveContext = stats._CurveContext( item=self.plot1d.getCurve('curve0'), plot=self.plot1d, onlimits=False) self.stat = stats.StatMin()
def plotHistogram(image): """display the pixel intensity distribution""" ## create the histogramnd # - using silx.math.histogram.Histogramnd # # - http://www.silx.org/doc/silx/dev/modules/math/histogram.html from silx.math.histogram import Histogramnd histo, w_histo, edges = Histogramnd(image.flatten(), n_bins=256, histo_range=[0,256]) plot=Plot1D() # ... TODO : plot the histogram1D using silx.gui.plot.Plot1d return plot
def get_plot_std(backend): x = numpy.arange(0, 10, step=0.1) my_sin = numpy.sin(x) y = numpy.arange(-4, 6, step=0.1) + my_sin mean = numpy.arange(-5, 5, step=0.1) + my_sin baseline = numpy.arange(-6, 4, step=0.1) + my_sin edges = x[y >= 3.0] histo = mean[y >= 3.0] - 1.8 plot = Plot1D(backend=backend) plot.addCurve(x=x, y=y, baseline=baseline, color='grey', legend='std-curve', fill=True) plot.addCurve(x=x, y=mean, color='red', legend='mean') plot.addHistogram(histogram=histo, edges=edges, color='red', legend='mean2', fill=True) return plot
def main(): global app app = qt.QApplication([]) # Create a Plot1D, set its limits and display it plot1d = Plot1D() plot1d.setLimits(0., 1000., 0., 1.) plot1d.show() # Create the thread that calls submitToQtMainThread updateThread = UpdateThread(plot1d) updateThread.start() # Start updating the plot app.exec_() updateThread.stop() # Stop updating the plot
def setUp(self): TestCaseQt.setUp(self) mystats = statshandler.StatsHandler( ((stats.StatMin(), statshandler.StatFormatter()), )) self.plot = Plot1D() self.plot.show() x = range(20) y = range(20) self.plot.addCurve(x, y, legend='curve0') y = range(12, 32) self.plot.addCurve(x, y, legend='curve1') y = range(-2, 18) self.plot.addCurve(x, y, legend='curve2') self.widget = StatsWidget.BasicGridStatsWidget(plot=self.plot, kind='curve', stats=mystats)
def setUp(self): self.plot = Plot1D() x = range(20) y = range(20) self.plot.addCurve(x, y, legend='curve0') self.listener = SignalListener() self.curves_roi_widget = self.plot.getCurvesRoiWidget() self.curves_roi_widget.sigROISignal.connect(self.listener) assert self.curves_roi_widget.isVisible() is False assert self.listener.callCount() == 0 self.plot.show() self.qWaitForWindowExposed(self.plot) toolButton = getQToolButtonFromAction(self.plot.getRoiAction()) self.mouseClick(widget=toolButton, button=qt.Qt.LeftButton) self.curves_roi_widget.show() self.qWaitForWindowExposed(self.curves_roi_widget)
def get_plot_stacked_histogram(backend): plot = Plot1D(backend=backend) # first histogram edges = numpy.arange(-6, 6, step=0.5) histo_1 = numpy.random.random(len(edges)) histo_2 = numpy.random.random(len(edges)) histo_3 = numpy.random.random(len(edges)) histo_4 = numpy.random.random(len(edges)) stacked_histogran(plot=plot, edges=edges, histograms=(histo_1, histo_2, histo_3, histo_4), colors=('blue', 'green', 'red', 'yellow'), legend='first_stacked_histo') # second histogram edges = numpy.arange(10, 25, step=1.0) histo_1 = -numpy.random.random(len(edges)) histo_2 = -numpy.random.random(len(edges)) stacked_histogran(plot=plot, histograms=(histo_1, histo_2), edges=edges, colors=('gray', 'black'), legend='second_stacked_histo') # last histogram edges = [30, 40] histograms = [ [0.2, 0.3], [0.0, 1.0], [0.1, 0.4], [0.2, 0.0], [0.6, 0.4], ] stacked_histogran(plot=plot, histograms=histograms, edges=edges, colors=('blue', 'green', 'red', 'yellow', 'cyan'), legend='third_stacked_histo') return plot
def __init__(self, parent=None): """ :param parent: Parent QWidget """ super(XYVScatterPlot, self).__init__(parent) self.__y_axis = None """1D array""" self.__y_axis_name = None self.__values = None """List of 1D arrays (for multiple scatters with identical x, y coordinates)""" self.__x_axis = None self.__x_axis_name = None self.__x_axis_errors = None self.__y_axis = None self.__y_axis_name = None self.__y_axis_errors = None self._plot = Plot1D(self) self._plot.setDefaultColormap( Colormap(name="viridis", vmin=None, vmax=None, normalization=Colormap.LINEAR)) self._slider = HorizontalSliderWithBrowser(parent=self) self._slider.setMinimum(0) self._slider.setValue(0) self._slider.valueChanged[int].connect(self._sliderIdxChanged) self._slider.setToolTip("Select auxiliary signals") layout = qt.QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._plot, 0, 0) layout.addWidget(self._slider, 1, 0) self.setLayout(layout)
def __init__(self, parent=None): """ :param parent: Parent QWidget """ super(ArrayCurvePlot, self).__init__(parent) self.__signal = None self.__signal_name = None self.__signal_errors = None self.__axis = None self.__axis_name = None self.__axis_errors = None self.__values = None self.__first_curve_added = False self._plot = Plot1D(self) self._plot.setDefaultColormap( # for scatters {"name": "viridis", "vmin": 0., "vmax": 1., # ignored (autoscale) but mandatory "normalization": "linear", "autoscale": True}) self.selectorDock = qt.QDockWidget("Data selector", self._plot) # not closable self.selectorDock.setFeatures(qt.QDockWidget.DockWidgetMovable | qt.QDockWidget.DockWidgetFloatable) self._selector = NumpyAxesSelector(self.selectorDock) self._selector.setNamedAxesSelectorVisibility(False) self.__selector_is_connected = False self.selectorDock.setWidget(self._selector) self._plot.addTabbedDockWidget(self.selectorDock) layout = qt.QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._plot, 0, 0) self.setLayout(layout)
def __init__(self, parent, data_to_fit=None): super().__init__(parent) self._data_to_fit = data_to_fit self._fitted_data = [] self.layout = QVBoxLayout(self) self.automatic_plot = Plot1D(self) self.fitting_data_selector = NumpyAxesSelector(self) self.fit = FitManager() self.fit.addtheory("pearson7", function=pearson7bg, parameters=[ 'backgr', 'slopeLin', 'amplitude', 'center', 'fwhm', 'exposant' ], estimate=estimate_pearson7) """ self.fitting_widget = self.fitting_data_plot.getFitAction() self.fit_action = FitAction(plot=self.fitting_data_plot, parent=self.fitting_data_plot) self.toolbar = QToolBar("New") """ self.init_ui()
def plot1Dsilx(nodeData): from silx.gui.plot import Plot1D saveType = nodeData[0] plot = Plot1D() plot.setGraphTitle(nodeData[1] + ' ' + saveType) plot.setGraphXLabel(label=nodeData[3][0]) plot.setGraphYLabel(label=nodeData[3][1], axis='left') if nodeData[3][2]: plot.setGraphYLabel(label=nodeData[3][2], axis='right') savedColumns = nodeData[4] for fname, props in savedColumns.items(): curves = read1D(saveType, fname, props) if len(props) > 3: yprops = props[3] clr = props[1] for curve in curves: x, ys, headers = curve for y, header in zip(ys, headers): try: kw = dict(yprops[header]) except KeyError: kw = {'yaxis': 'left'} clr = 'gray' symbolsize = kw.pop('symbolsize', 2) symbol = kw.get('symbol', None) lbl = props[0] + '.' + header plot.addCurve(x, y, color=clr, legend=lbl, **kw) if symbol is not None: curve = plot.getCurve(lbl) if curve is not None: curve.setSymbolSize(symbolsize) plot.show() # end plot1Dsilx
def main(argv): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--update-mode', default='auto', help='update mode to display (manual or auto)') options = parser.parse_args(argv[1:]) app = qt.QApplication([]) plot = Plot1D() # Create the thread that calls submitToQtMainThread updateThread = UpdateThread(plot) updateThread.start() # Start updating the plot plot.addScatter(x=[0, 2, 5, 5, 12, 20], y=[2, 3, 4, 20, 15, 6], value=[5, 6, 7, 10, 90, 20], colormap=Colormap('viridis'), legend='myScatter') stats = [ ('sum', numpy.sum), Integral(), (COM(), '{0:.2f}'), ] plot.getStatsWidget().setStats(stats) plot.getStatsWidget().setUpdateMode(options.update_mode) plot.getStatsWidget().setDisplayOnlyActiveItem(False) plot.getStatsWidget().parent().setVisible(True) plot.show() app.exec() updateThread.stop() # Stop updating the plot
replot=False) MENU_TEXT = "Remove glitches from curves" def getPlugin1DInstance(plotWindow, **kw): ob = MedianFilterScanDeglitchPlugin(plotWindow) return ob if __name__ == "__main__": from silx.gui.plot import Plot1D app = qt.QApplication([]) sw = Plot1D() x = numpy.linspace(0, 1999, 2000) y0 = x / 100. + 100. * numpy.exp(-(x - 500)**2 / 1000.) + 50. * numpy.exp( -(x - 1200)**2 / 5000.) + 100. * numpy.exp( -(x - 1700)**2 / 500.) + 10 * numpy.random.random(2000) y1 = x / 100. + 100. * numpy.exp(-(x - 600)**2 / 1000.) + 50. * numpy.exp( -(x - 1000)**2 / 5000.) + 100. * numpy.exp( -(x - 1500)**2 / 500.) + 10 * numpy.random.random(2000) for idx in range(20): y0[idx * 100] = 500. * numpy.random.random(1) y1[idx * 100] = 500. * numpy.random.random(1) sw.addCurve(x, y0, legend="Curve0") sw.addCurve(x, y1, legend="Curve1")
def createWidget(self, parent): plot = Plot1D(parent=parent) plot.setAutoReplot(False) return plot
# it is not possible to share kernel with ipython so we need to launch it directly from python from silx.gui import qt from silx.gui.plot import Plot1D app = qt.QApplication([]) p=Plot1D() p.addCurve(range(20), range(20)) p.show() # then play with the options button app.exec_()
text='Clear', tooltip='Clear the plot', triggered=self._clear, parent=parent) def _clear(self): """Handle action triggered and clear the plot""" self.plot.clear() if __name__ == '__main__': from silx.gui import qt from silx.gui.plot import Plot1D app = qt.QApplication([]) # First create QApplication plot = Plot1D() # Create plotting widget # Create a toolbar and add it to the plot widget toolbar = qt.QToolBar() plot.addToolBar(toolbar) # Create clear action and add it to the toolbar action = ClearPlotAction(plot, parent=plot) toolbar.addAction(action) plot.addCurve((0, 1, 2, 3, 4), (0, 1, 1.5, 1, 0)) # Add a curve to the plot plot.show() # Show the plot widget app.exec() # Start Qt application
t = Timer(execPymca) execTime["pymca"] = t.timeit(BenchmarkMedianFilter.NB_ITER) logger.info('exec time pymca (kernel size = %s) is %s' % (width, execTime["pymca"])) return execTime def getExecTimeFor(self, id): res = [] for k in self.kernels: res.append(self.execTime[k][id]) return res app = qt.QApplication([]) kernels = [3, 5, 7, 11, 15] benchmark = BenchmarkMedianFilter(imageWidth=1000, kernels=kernels) plot = Plot1D() plot.addCurve(x=kernels, y=benchmark.getExecTimeFor("silx"), legend='silx') if scipy is not None: plot.addCurve(x=kernels, y=benchmark.getExecTimeFor("scipy"), legend='scipy') if pymca is not None: plot.addCurve(x=kernels, y=benchmark.getExecTimeFor("pymca"), legend='pymca') plot.show() app.exec() del app