예제 #1
0
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?')
예제 #2
0
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
예제 #3
0
    def _plot(self):
        """
        Plots results.
        """

        if self._plot_type == 'spectra':
            from mantidplot import plotSpectrum
            num_spectra = mtd[self._plot_ws].getNumberHistograms()
            try:
                plotSpectrum(self._plot_ws, range(0, num_spectra))
            except RuntimeError:
                logger.notice('Spectrum plotting canceled by user')

        if self._plot_type == 'contour':
            from mantidplot import importMatrixWorkspace
            plot_workspace = importMatrixWorkspace(self._plot_ws)
            plot_workspace.plotGraph2D()
예제 #4
0
def plot_reduction(workspace_name, plot_type):
    """
    Plot a given workspace based on the Plot property.

    @param workspace_name Name of workspace to plot
    @param plot_type Type of plot to create
    """

    if plot_type == 'Spectra' or plot_type == 'Both':
        from mantidplot import plotSpectrum
        num_spectra = mtd[workspace_name].getNumberHistograms()
        try:
            plotSpectrum(workspace_name, range(0, num_spectra))
        except RuntimeError:
            logger.notice('Spectrum plotting canceled by user')

    can_plot_contour = mtd[workspace_name].getNumberHistograms() > 1
    if (plot_type == 'Contour' or plot_type == 'Both') and can_plot_contour:
        from mantidplot import importMatrixWorkspace
        plot_workspace = importMatrixWorkspace(workspace_name)
        plot_workspace.plotGraph2D()
예제 #5
0
def plot_reduction(workspace_name, plot_type):
    """
    Plot a given workspace based on the Plot property.

    @param workspace_name Name of workspace to plot
    @param plot_type Type of plot to create
    """

    if plot_type == 'Spectra' or plot_type == 'Both':
        from mantidplot import plotSpectrum
        num_spectra = mtd[workspace_name].getNumberHistograms()
        try:
            plotSpectrum(workspace_name, range(0, num_spectra))
        except RuntimeError:
            logger.notice('Spectrum plotting canceled by user')

    can_plot_contour = mtd[workspace_name].getNumberHistograms() > 1
    if (plot_type == 'Contour' or plot_type == 'Both') and can_plot_contour:
        from mantidplot import importMatrixWorkspace
        plot_workspace = importMatrixWorkspace(workspace_name)
        plot_workspace.plotGraph2D()
예제 #6
0
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?')