Beispiel #1
0
 def _action_double_click_workspace(self, name):
     ws = self._ads.retrieve(name)
     try:
         # if this is a table workspace (or peaks workspace),
         # then it can't be plotted automatically, so the data is shown instead
         TableWorkspaceDisplay.supports(ws)
         self._do_show_data([name])
     except ValueError:
         if hasattr(ws, 'blocksize') and ws.blocksize() == 1:
             #If this is ws is just a single value show the data, else plot the bin
             if hasattr(ws, 'getNumberHistograms'
                        ) and ws.getNumberHistograms() == 1:
                 self._do_show_data([name])
             else:
                 plot_kwargs = {"axis": MantidAxType.BIN}
                 plot([ws],
                      errors=False,
                      overplot=False,
                      wksp_indices=[0],
                      plot_kwargs=plot_kwargs)
         else:
             plot_from_names([name],
                             errors=False,
                             overplot=False,
                             show_colorfill_btn=True)
Beispiel #2
0
    def _plot_on_here(self, names, ax):
        """
        Assume the list of strings refer to workspace names and they are to be plotted
        on this figure. If the current figure contains an image plot then
        a new image plot will replace the current image. If the current figure
        contains a line plot then the user will be asked what should be plotted and this
        will overplot onto the figure. If the first line of the plot
        :param names: A list of workspace names
        :param ax: The matplotlib axes object to overplot onto
        """
        if len(names) == 0:
            return
        # local import to avoid circular import with FigureManager
        from mantidqt.plotting.functions import pcolormesh, plot_from_names, plot_surface, plot_wireframe, plot_contour

        fig = self._canvas.figure
        fig_type = figure_type(fig, ax)
        if fig_type == FigureType.Image:
            pcolormesh(names, fig=fig)
        elif fig_type == FigureType.Surface:
            plot_surface(names, fig=fig)
        elif fig_type == FigureType.Wireframe:
            plot_wireframe(names, fig=fig)
        elif fig_type == FigureType.Contour:
            plot_contour(names, fig=fig)
        else:
            plot_from_names(names, errors=(fig_type == FigureType.Errorbar),
                            overplot=ax, fig=fig)
 def test_plot_from_names_calls_plot(self, get_spectra_selection_mock, plot_mock):
     ws_name = 'test_plot_from_names_calls_plot-1'
     AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws)
     selection = SpectraSelection([self._test_ws])
     selection.wksp_indices = [0]
     get_spectra_selection_mock.return_value = selection
     plot_from_names([ws_name], errors=False, overplot=False)
     self.assertEqual(1, plot_mock.call_count)
Beispiel #4
0
 def _action_double_click_workspace(self, name):
     try:
         # if this is a table workspace (or peaks workspace),
         # then it can't be plotted automatically, so the data is shown instead
         TableWorkspaceDisplay.supports(self._ads.retrieve(name))
         self._do_show_data([name])
     except ValueError:
         plot_from_names([name], errors=False, overplot=False, show_colorfill_btn=True)
Beispiel #5
0
    def test_plot_from_names_calls_plot(self, get_spectra_selection_mock, plot_mock):
        ws_name = 'test_plot_from_names_calls_plot-1'
        AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws)
        selection = SpectraSelection([self._test_ws])
        selection.wksp_indices = [0]
        get_spectra_selection_mock.return_value = selection
        plot_from_names([ws_name], errors=False, overplot=False)

        self.assertEqual(1, plot_mock.call_count)
Beispiel #6
0
    def _do_plot_spectrum(self, names, errors, overplot, advanced=False):
        """
        Plot spectra from the selected workspaces

        :param names: A list of workspace names
        :param errors: If true then error bars will be plotted on the points
        :param overplot: If true then the add to the current figure if one
                         exists and it is a compatible figure
        :param advanced: If true then the advanced options will be shown in
                         the spectra selector dialog.
        """
        try:
            plot_from_names(names, errors, overplot, advanced=advanced)
        except RuntimeError as re:
            logger.error(str(re))
    def _do_plot_spectrum(self, names, errors, overplot):
        """
        Plot spectra from the selected workspaces

        :param names: A list of workspace names
        :param errors: If true then error bars will be plotted on the points
        :param overplot: If true then the add to the current figure if one
                         exists and it is a compatible figure
        """
        if overplot:
            compatible, error_msg = can_overplot()
            if not compatible:
                QMessageBox.warning(self, "", error_msg)
                return

        plot_from_names(names, errors, overplot)
Beispiel #8
0
    def _do_plot_from_names_test(self,
                                 get_spectra_selection_mock,
                                 expected_labels,
                                 wksp_indices,
                                 errors,
                                 overplot,
                                 target_fig=None):
        ws_name = 'test_plot_from_names-1'
        AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws)

        selection = SpectraSelection([self._test_ws])
        selection.wksp_indices = wksp_indices
        get_spectra_selection_mock.return_value = selection
        fig = plot_from_names([ws_name], errors, overplot, target_fig)
        if target_fig is not None:
            self.assertEqual(target_fig, fig)

        plotted_lines = fig.gca().get_legend().get_lines()
        self.assertEqual(len(expected_labels), len(plotted_lines))
        for label_part, line in zip(expected_labels, plotted_lines):
            if label_part is not None:
                self.assertTrue(
                    label_part in line.get_label(),
                    msg="Label fragment '{}' not found in line label".format(
                        label_part))
        return fig
Beispiel #9
0
    def _create_plot(self, names, errors, overplot, wksp_indices=None, plot_type=SpectraSelection.Tiled, fig=None):
        selection = SpectraSelection(names)
        selection.wksp_indices = wksp_indices if wksp_indices else [0]
        selection.plot_type = plot_type
        self.get_spectra_selection_mock.return_value = selection

        return plot_from_names(names=names, errors=errors, overplot=overplot, fig=fig)
Beispiel #10
0
    def _do_plot_spectrum(self, names, errors, overplot):
        """
        Plot spectra from the selected workspaces

        :param names: A list of workspace names
        :param errors: If true then error bars will be plotted on the points
        :param overplot: If true then the add to the current figure if one
                         exists and it is a compatible figure
        """
        if overplot:
            compatible, error_msg = can_overplot()
            if not compatible:
                QMessageBox.warning(self, "", error_msg)
                return

        plot_from_names(names, errors, overplot)
Beispiel #11
0
 def _action_double_click_workspace(self, name):
     ws = self._ads.retrieve(name)
     try:
         # if this is a table workspace (or peaks workspace),
         # then it can't be plotted automatically, so the data is shown instead
         TableWorkspaceDisplay.supports(ws)
         self._do_show_data([name])
     except ValueError:
         if ws.blocksize() == 1:
             #this is just single bin data, it makes more sense to plot the bin
             plot_kwargs = {"axis": MantidAxType.BIN}
             plot([ws],
                  errors=False,
                  overplot=False,
                  wksp_indices=[0],
                  plot_kwargs=plot_kwargs)
         else:
             plot_from_names([name],
                             errors=False,
                             overplot=False,
                             show_colorfill_btn=True)
Beispiel #12
0
    def _plot_on_here(self, names):
        """
        Assume the list of strings refer to workspace names and they are to be plotted
        on this figure. If the current figure contains an image plot then
        a new image plot will replace the current image. If the current figure
        contains a line plot then the user will be asked what should be plotted and this
        will overplot onto the figure. If the first line of the plot
        :param names: A list of workspace names
        """
        if len(names) == 0:
            return
        # local import to avoid circular import with FigureManager
        from mantidqt.plotting.functions import pcolormesh_from_names, plot_from_names

        fig = self._canvas.figure
        fig_type = figure_type(fig)
        if fig_type == FigureType.Image:
            pcolormesh_from_names(names, fig=fig)
        else:
            plot_from_names(names, errors=(fig_type == FigureType.Errorbar),
                            overplot=True, fig=fig)
Beispiel #13
0
    def _do_plot_from_names_test(self, get_spectra_selection_mock, expected_labels,
                                 wksp_indices, errors, overplot, target_fig=None):
        ws_name = 'test_plot_from_names-1'
        AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws)

        selection = SpectraSelection([self._test_ws])
        selection.wksp_indices = wksp_indices
        get_spectra_selection_mock.return_value = selection
        fig = plot_from_names([ws_name], errors, overplot, target_fig)
        if target_fig is not None:
            self.assertEqual(target_fig, fig)

        plotted_lines = fig.gca().get_legend().get_lines()
        self.assertEqual(len(expected_labels), len(plotted_lines))
        for label_part, line in zip(expected_labels, plotted_lines):
            if label_part is not None:
                self.assertTrue(label_part in line.get_label(),
                                msg="Label fragment '{}' not found in line label".format(label_part))
        return fig
Beispiel #14
0
 def test_plot_from_names_with_non_plottable_workspaces_returns_None(self):
     table = WorkspaceFactory.Instance().createTable()
     table_name = 'test_plot_from_names_with_non_plottable_workspaces_returns_None'
     AnalysisDataService.Instance().addOrReplace(table_name, table)
     result = plot_from_names([table_name], errors=False, overplot=False)
     self.assertEqual(result, None)
Beispiel #15
0
 def test_plot_from_names_with_non_plottable_workspaces_returns_None(self):
     table = WorkspaceFactory.Instance().createTable()
     table_name = 'test_plot_from_names_with_non_plottable_workspaces_returns_None'
     AnalysisDataService.Instance().addOrReplace(table_name, table)
     result = plot_from_names([table_name], errors=False, overplot=False)
     self.assertTrue(result is None)