def plot_graphs(self, i, reduced_files_path, base_output_name, output_workspace, plot_2D, plot1Dgraph): if mantidplot: if self.reduce_2D: plot2Dgraph = mantidplot.plot2D(base_output_name) n_2D = output_workspace.name() + '.png' SavePlot = os.path.join(os.path.expanduser(reduced_files_path), n_2D) plot2Dgraph.export(SavePlot) print("2D File Exists:{}".format(os.path.exists(SavePlot))) # is there more elegant way to do it? # Problem is that plot2Dgraph creates and plot the graph file at the same time... if not plot_2D: plot2Dgraph.close() else: if i == 0: # to create first graph to stick all the rest to it; perhaps there is more elegant way # of creating initial empty handler, but I am not aware ... yet plot1Dgraph = mantidplot.plotSpectrum( base_output_name, 0, distribution=mantidplot.DistrFlag.DistrFalse, clearWindow=False) else: mantidplot.mergePlots( plot1Dgraph, mantidplot.plotSpectrum( base_output_name, 0, distribution=mantidplot.DistrFlag.DistrFalse, clearWindow=False))
def PlotResult(workspace, canvas=None): """ Draws a graph of the passed workspace. If the workspace is 2D (has many spectra a contour plot is written @param workspace: a workspace name or handle to plot @param canvas: optional handle to an existing graph to write the plot to @return: a handle to the graph that was written to """ raise NotImplementedError(_plot_missing_str) try: import mantidplot workspace = AnalysisDataService.retrieve(str(workspace)) number_of_spectra = workspace[0].getNumberHistograms() if isinstance(workspace, WorkspaceGroup) else\ workspace.getNumberHistograms() graph = mantidplot.plotSpectrum(workspace, 0) if number_of_spectra == 1 else \ mantidplot.importMatrixWorkspace(workspace.name()).plotGraph2D() if canvas is not None: # we were given a handle to an existing graph, use it mantidplot.mergePlots(canvas, graph) graph = canvas return graph except ImportError: print_message('Plot functions are not available, is this being run from outside Mantidplot?')
def PlotResult(workspace, canvas=None): """ Draws a graph of the passed workspace. If the workspace is 2D (has many spectra a contour plot is written @param workspace: a workspace name or handle to plot @param canvas: optional handle to an existing graph to write the plot to @return: a handle to the graph that was written to """ #ensure that we are dealing with a workspace handle rather than its name workspace = mtd[str(workspace)] if workspace.isGroup(): numSpecs = workspace[0].getNumberHistograms() else: numSpecs = workspace.getNumberHistograms() try: if numSpecs == 1: graph = mantidplot.plotSpectrum(workspace,0) else: graph = mantidplot.importMatrixWorkspace(workspace.getName()).plotGraph2D() except NameError: issueWarning('Plot functions are not available, is this being run from outside Mantidplot?') if not canvas is None: #we were given a handle to an existing graph, use it mantidplot.mergePlots(canvas, graph) graph = canvas return graph
def plot_graphs(self, i, reduced_files_path, base_output_name, output_workspace, plot_2D, plot1Dgraph): if mantidplot: if self.reduce_2D: plot2Dgraph = mantidplot.plot2D(base_output_name) n_2D = output_workspace.name() + '.png' SavePlot = os.path.join(os.path.expanduser(reduced_files_path), n_2D) plot2Dgraph.export(SavePlot) print("2D File Exists:{}".format(os.path.exists(SavePlot))) # is there more elegant way to do it? # Problem is that plot2Dgraph creates and plot the graph file at the same time... if not plot_2D: plot2Dgraph.close() else: if i == 0: # to create first graph to stick all the rest to it; perhaps there is more elegant way # of creating initial empty handler, but I am not aware ... yet plot1Dgraph = mantidplot.plotSpectrum(base_output_name, 0, distribution=mantidplot.DistrFlag.DistrFalse, clearWindow=False) else: mantidplot.mergePlots(plot1Dgraph, mantidplot.plotSpectrum(base_output_name, 0, distribution=mantidplot.DistrFlag.DistrFalse, clearWindow=False))
def PyExec(self): import mantidplot as mp workdir = config['defaultsave.directory'] self._setup() DeconApplyCorrections(DataWorkspace=self._stheta, DerivativesWorkspace=self._deriv, MomentsWorkspace=self._mome, UseSmoothData=self._smooth, NumberTerms=self._nterms, Cutoff=self._cutoff, CutoffPoint=self._cutoff_pt) DeconD4Result(CorrectedWorkspace=self._stheta + '_corrected', QWorkspace=self._sofq, RebinOption='None', RebinQrange=self._rebin_qrange, RebinQinc=self._rebin_qinc) if self._plot: mp.plotSpectrum(self._stheta + '_coeff', [0,1,2,3]) mp.plotSpectrum(self._stheta + '_corr', [0,1,2,3]) result_graph=mp.plotSpectrum(self._stheta + '_result', [0,1,2,3], False) mp.mergePlots(result_graph,mp.plotSpectrum(self._stheta + '_used', 0, False)) self._plot_result([self._stheta + '_used', self._stheta + '_corrected'], 0) finalQ_graph=mp.plotSpectrum(self._sofq + '_corrected', 0, False) finalQ_layer = finalQ_graph.activeLayer() finalQ_layer.setAxisTitle(mp.Layer.Bottom, 'Q') mp.mergePlots(finalQ_graph,mp.plotSpectrum(self._sofq, 0, False)) if self._saveNXS: save_nxs_prog = Progress(self, start=0.0, end=0.8, nreports=4) save_nxs_prog.report('Save NXS ') self._save_ws(self._stheta + '_coeff', 'Coefficients') self._save_ws(self._stheta + '_corr', 'Corrections') self._save_ws(self._stheta + '_result', 'Result') self._save_ws(self._stheta + '_corrected', 'Final theta corrected') self._save_ws(self._sofq + '_corrected', 'Final Q corrected') save_nxs_prog.report('Save NXS completed') if self._saveAscii: save_ascii_prog = Progress(self, start=0.0, end=0.8, nreports=3) save_ascii_prog.report('Save ascii ') self._save_Ascii(self._stheta + '_corrected', '.stc') self._save_Ascii(self._sofq + '_corrected', '.sqc') save_ascii_prog.report('Save ascii completed')
def PlotResult(workspace, canvas=None): """ Draws a graph of the passed workspace. If the workspace is 2D (has many spectra a contour plot is written @param workspace: a workspace name or handle to plot @param canvas: optional handle to an existing graph to write the plot to @return: a handle to the graph that was written to """ try: import mantidplot workspace = AnalysisDataService.retrieve(str(workspace)) number_of_spectra = workspace[0].getNumberHistograms() if isinstance(workspace, WorkspaceGroup) else\ workspace.getNumberHistograms() graph = mantidplot.plotSpectrum(workspace, 0) if number_of_spectra == 1 else \ mantidplot.importMatrixWorkspace(workspace.getName()).plotGraph2D() if canvas is not None: # we were given a handle to an existing graph, use it mantidplot.mergePlots(canvas, graph) graph = canvas return graph except ImportError: print_message('Plot functions are not available, is this being run from outside Mantidplot?')