MENU_TEXT = "Alignment Plugin" def getPlugin1DInstance(plotWindow, **kw): ob = AlignmentScanPlugin(plotWindow) return ob if __name__ == "__main__": import os try: from PyMca5.PyMcaGui import PyMcaQt as qt from PyMca5.PyMcaGui.plotting import PlotWindow app = qt.QApplication([]) QT = True plot = PlotWindow.PlotWindow() except: # test without graphical interface QT = False from PyMca5.PyMcaGraph import Plot plot = Plot.Plot() pluginDir = [os.path.dirname(__file__)] plot.getPlugins(method="getPlugin1DInstance", directoryList=pluginDir) i = numpy.arange(1000.) y1 = 10.0 + 5000.0 * numpy.exp(-0.01 * (i - 50)**2) y2 = 10.0 + 5000.0 * numpy.exp(-((i - 55) / 5.)**2) plot.addCurve(i, y1, "y1") plot.addCurve(i, y2, "y2") plugin = getPlugin1DInstance(plot) for method in plugin.getMethods(): print(method, ":", plugin.getMethodToolTip(method))
def plot_results(self): self.plotted_beam = None if super().plot_results(): if self.spectro_plot_canvas is None: self.spectro_plot_canvas = PlotWindow.PlotWindow( roi=False, control=False, position=False, plugins=False, logx=False, logy=False) self.spectro_plot_canvas.setDefaultPlotLines(False) self.spectro_plot_canvas.setDefaultPlotPoints(True) self.spectro_plot_canvas.setZoomModeEnabled(True) self.spectro_plot_canvas.setMinimumWidth(673) self.spectro_plot_canvas.setMaximumWidth(673) pos = self.spectro_plot_canvas._plot.graph.ax.get_position() self.spectro_plot_canvas._plot.graph.ax.set_position( [pos.x0, pos.y0, pos.width * 0.86, pos.height]) pos = self.spectro_plot_canvas._plot.graph.ax2.get_position() self.spectro_plot_canvas._plot.graph.ax2.set_position( [pos.x0, pos.y0, pos.width * 0.86, pos.height]) ax3 = self.spectro_plot_canvas._plot.graph.fig.add_axes( [.82, .15, .05, .75]) self.spectro_image_box.layout().addWidget( self.spectro_plot_canvas) else: self.spectro_plot_canvas.clear() self.spectro_plot_canvas.setDefaultPlotLines(False) self.spectro_plot_canvas.setDefaultPlotPoints(True) ax3 = self.spectro_plot_canvas._plot.graph.fig.axes[-1] ax3.cla() number_of_bins = self.spectro_number_of_bins + 1 x, y, auto_x_title, auto_y_title, xum, yum = self.get_titles() if self.plotted_beam is None: self.plotted_beam = self.input_beam xrange, yrange = self.get_ranges(self.plotted_beam._beam, x, y) min_k = numpy.min(self.plotted_beam._beam.rays[:, 10]) max_k = numpy.max(self.plotted_beam._beam.rays[:, 10]) if self.spectro_variable == 0: #Energy energy_min = ShadowPhysics.getEnergyFromShadowK(min_k) energy_max = ShadowPhysics.getEnergyFromShadowK(max_k) bins = energy_min + numpy.arange(0, number_of_bins + 1) * ( (energy_max - energy_min) / number_of_bins) normalization = colors.Normalize(vmin=energy_min, vmax=energy_max) else: #wavelength wavelength_min = ShadowPhysics.getWavelengthfromShadowK(max_k) wavelength_max = ShadowPhysics.getWavelengthfromShadowK(min_k) bins = wavelength_min + numpy.arange(0, number_of_bins + 1) * ( (wavelength_max - wavelength_min) / number_of_bins) normalization = colors.Normalize(vmin=wavelength_min, vmax=wavelength_max) scalarMap = cmx.ScalarMappable(norm=normalization, cmap=self.color_map) cb1 = colorbar.ColorbarBase(ax3, cmap=self.color_map, norm=normalization, orientation='vertical') if self.spectro_variable == 0: #Energy cb1.set_label('Energy [eV]') else: cb1.set_label('Wavelength [Å]') go = numpy.where(self.plotted_beam._beam.rays[:, 9] == 1) lo = numpy.where(self.plotted_beam._beam.rays[:, 9] != 1) rays_to_plot = self.plotted_beam._beam.rays if self.rays == 1: rays_to_plot = self.plotted_beam._beam.rays[go] elif self.rays == 2: rays_to_plot = self.plotted_beam._beam.rays[lo] factor_x = ShadowPlot.get_factor(x, self.workspace_units_to_cm) factor_y = ShadowPlot.get_factor(y, self.workspace_units_to_cm) for index in range(0, number_of_bins): min_value = bins[index] max_value = bins[index + 1] if index < number_of_bins - 1: if self.spectro_variable == 0: #Energy cursor = numpy.where((numpy.round( ShadowPhysics.getEnergyFromShadowK( rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) & (numpy.round( ShadowPhysics.getEnergyFromShadowK( rays_to_plot[:, 10]), 4) < numpy.round( max_value, 4))) else: cursor = numpy.where((numpy.round( ShadowPhysics.getWavelengthfromShadowK( rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) & (numpy.round( ShadowPhysics.getWavelengthfromShadowK( rays_to_plot[:, 10]), 4) < numpy.round( max_value, 4))) else: if self.spectro_variable == 0: #Energy cursor = numpy.where((numpy.round( ShadowPhysics.getEnergyFromShadowK( rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) & (numpy.round( ShadowPhysics.getEnergyFromShadowK( rays_to_plot[:, 10]), 4) <= numpy.round( max_value, 4))) else: cursor = numpy.where((numpy.round( ShadowPhysics.getWavelengthfromShadowK( rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) & (numpy.round( ShadowPhysics.getWavelengthfromShadowK( rays_to_plot[:, 10]), 4) <= numpy.round( max_value, 4))) color = scalarMap.to_rgba((bins[index] + bins[index + 1]) / 2) if index == 0: self.spectro_plot_canvas.setActiveCurveColor(color=color) self.replace_spectro_fig(rays_to_plot[cursor], x, y, factor_x, factor_y, title=self.title + str(index), color=color) self.spectro_plot_canvas.setGraphXLimits(xrange[0] * factor_x, xrange[1] * factor_x) self.spectro_plot_canvas.setGraphYLimits(yrange[0] * factor_y, yrange[1] * factor_y) self.spectro_plot_canvas.setGraphXLabel(auto_x_title) self.spectro_plot_canvas.setGraphYLabel(auto_y_title) self.spectro_plot_canvas.replot()
def __init__(self, parent=None, fit=None, graph=None, actions=True): qt.QWidget.__init__(self, parent) self.setWindowTitle("SimpleFitGui") if fit is None: self.fitModule = SimpleFitModule.SimpleFit() self.fitModule.importFunctions(SimpleFitUserEstimatedFunctions) self.fitModule.loadUserFunctions() else: self.fitModule = fit if graph is None: self.__useTab = True self.graph = PlotWindow.PlotWindow(newplot=False, plugins=False, fit=False, control=True, position=True) else: self.__useTab = False self.graph = graph self._configurationDialog = None self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setContentsMargins(2, 2, 2, 2) self.mainLayout.setSpacing(2) self.topWidget = TopWidget(self) config = self.fitModule.getConfiguration() self.topWidget.setFunctions(config['fit']['functions']) config = None if self.__useTab: self.mainTab = qt.QTabWidget(self) self.mainLayout.addWidget(self.mainTab) self.parametersTable = Parameters.Parameters() self.mainTab.addTab(self.graph, 'GRAPH') self.mainTab.addTab(self.parametersTable, 'FIT') else: self.parametersTable = Parameters.Parameters(self) self.statusWidget = StatusWidget(self) self.mainLayout.addWidget(self.topWidget) if self.__useTab: self.mainLayout.addWidget(self.mainTab) else: self.mainLayout.addWidget(self.parametersTable) self.mainLayout.addWidget(self.statusWidget) if actions: #build the actions widget self.fitActions = qt.QWidget(self) self.fitActions.mainLayout = qt.QHBoxLayout(self.fitActions) self.fitActions.mainLayout.setContentsMargins(2, 2, 2, 2) self.fitActions.mainLayout.setSpacing(2) self.fitActions.estimateButton = qt.QPushButton(self.fitActions) self.fitActions.estimateButton.setText("Estimate") self.fitActions.startFitButton = qt.QPushButton(self.fitActions) self.fitActions.startFitButton.setText("Start Fit") self.fitActions.dismissButton = qt.QPushButton(self.fitActions) self.fitActions.dismissButton.setText("Dismiss") self.fitActions.mainLayout.addWidget(self.fitActions.estimateButton) self.fitActions.mainLayout.addWidget(self.fitActions.startFitButton) self.fitActions.mainLayout.addWidget(self.fitActions.dismissButton) self.mainLayout.addWidget(self.fitActions) #connect top widget self.topWidget.addFunctionButton.clicked.connect(\ self.importFunctionsSlot) self.topWidget.fitFunctionCombo.currentIndexChanged[int].connect(\ self.fitFunctionComboSlot) self.topWidget.backgroundCombo.currentIndexChanged[int].connect(\ self.backgroundComboSlot) self.topWidget.configureButton.clicked.connect(\ self.configureButtonSlot) if actions: #connect actions self.fitActions.estimateButton.clicked.connect(self.estimate) self.fitActions.startFitButton.clicked.connect(self.startFit) self.fitActions.dismissButton.clicked.connect(self.dismiss)
def testShow(self): from PyMca5.PyMcaGui.plotting import PlotWindow widget = PlotWindow.PlotWindow() widget.show() self.qapp.processEvents()