예제 #1
0
    def remove_workspace_info_from_plot(
            self, workspace_plot_info_list: List[WorkspacePlotInformation]):
        # We reverse the workspace info list so that we can maintain a unique color queue
        # See _update_color_queue_on_workspace_removal for more
        workspace_plot_info_list.reverse()
        for workspace_plot_info in workspace_plot_info_list:
            workspace_name = workspace_plot_info.workspace_name
            if not AnalysisDataService.Instance().doesExist(workspace_name):
                continue

            workspace = AnalysisDataService.Instance().retrieve(workspace_name)
            for plotted_information in self._plot_information_list.copy():
                if workspace_plot_info.workspace_name == plotted_information.workspace_name and \
                        workspace_plot_info.axis == plotted_information.axis:
                    self._update_color_queue_on_workspace_removal(
                        workspace_plot_info.axis, workspace_name)
                    axis = self.fig.axes[workspace_plot_info.axis]
                    axis.remove_workspace_artists(workspace)
                    self._plot_information_list.remove(plotted_information)
                    # clear shaded regions from plot
                    if len(
                            axis.collections
                    ) > 0 and plotted_information.workspace_name in self._shaded_regions.keys(
                    ):
                        self._shaded_regions[
                            plotted_information.workspace_name].remove()
        # If we have no plotted lines, reset the color cycle
        if self.num_plotted_workspaces == 0:
            self._reset_color_cycle()
예제 #2
0
 def remove_workspace_names_from_plot(self, workspace_names: List[str]):
     """Removes the input workspace names from the plot"""
     for workspace_name in workspace_names:
         try:
             workspace = AnalysisDataService.Instance().retrieve(workspace_name)
         except RuntimeError:
             continue
         self._view.remove_workspace_from_plot(workspace)
     self._view.redraw_figure()
예제 #3
0
 def _validate_workspaces(workspaces):
     """
     This method checks if any of the workspaces to plot contain NaN values.
     :param workspaces: A list of workspace names
     :return: A list of workspaces (used in matplotlib plotting). Raises if NaN values present.
     """
     workspaces = AnalysisDataService.Instance().retrieveWorkspaces(workspaces, unrollGroups=True)
     for ws in workspaces:
         if np.isnan(ws.readY(0)).any():
             # All data can be NaN if bounds are too close together
             # this makes the data unplottable
             raise ValueError("Workspace contains NaN values.")
     return workspaces
예제 #4
0
    def remove_workspace_info_from_plot(
            self, workspace_plot_info_list: List[WorkspacePlotInformation]):
        for workspace_plot_info in workspace_plot_info_list:
            workspace_name = workspace_plot_info.workspace_name
            try:
                workspace = AnalysisDataService.Instance().retrieve(
                    workspace_name)
            except RuntimeError:
                continue
            for plotted_information in self._plot_information_list.copy():
                if workspace_plot_info == plotted_information:
                    axis = self.fig.axes[workspace_plot_info.axis]
                    axis.remove_workspace_artists(workspace)
                    self._plot_information_list.remove(plotted_information)

        # If we have no plotted lines, reset the color cycle
        if self.num_plotted_workspaces == 0:
            self._reset_color_cycle()
예제 #5
0
 def _make_plot(self, workspace_plot_info: WorkspacePlotInformation):
     workspace_name = workspace_plot_info.workspace_name
     try:
         workspace = AnalysisDataService.Instance().retrieve(workspace_name)
     except (RuntimeError, KeyError):
         return -1
     self._plot_information_list.append(workspace_plot_info)
     errors = workspace_plot_info.errors
     ws_index = workspace_plot_info.index
     axis_number = workspace_plot_info.axis
     ax = self.fig.axes[axis_number]
     plot_kwargs = self._get_plot_kwargs(workspace_plot_info)
     plot_kwargs['color'] = self._color_queue[axis_number]()
     _do_single_plot(ax,
                     workspace,
                     ws_index,
                     errors=errors,
                     plot_kwargs=plot_kwargs)
     return axis_number
예제 #6
0
 def add_workspaces_to_plot(
         self, workspace_plot_info_list: List[WorkspacePlotInformation]):
     """Add a list of workspaces to the plot - The workspaces are contained in a list PlotInformation
     The PlotInformation contains the workspace name, workspace index and target axis."""
     for workspace_plot_info in workspace_plot_info_list:
         workspace_name = workspace_plot_info.workspace_name
         try:
             workspace = AnalysisDataService.Instance().retrieve(
                 workspace_name)
         except RuntimeError:
             continue
         self._plot_information_list.append(workspace_plot_info)
         errors = workspace_plot_info.errors
         ws_index = workspace_plot_info.index
         axis_number = workspace_plot_info.axis
         ax = self.fig.axes[axis_number]
         _do_single_plot(
             ax,
             workspace,
             ws_index,
             errors=errors,
             plot_kwargs=self._get_plot_kwargs(workspace_plot_info))
 def tearDown(self):
     AnalysisDataService.Instance().clear()