示例#1
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)
示例#2
0
 def test_hidden_fit_for_images(self):
     if 'ws1' in mtd:
         ws1 = mtd['ws1']
     else:
         ws1 = Load(r'emu00006473.nxs', OutputWorkspace='ws1')[0]
     pcolormesh([ws1])
     manager = GlobalFigureManager.get_active()
     action = manager.toolbar._actions['toggle_fit']
     self.assertFalse(action.isVisible())
     self.assertFalse(action.isEnabled())
示例#3
0
    def _do_plot_colorfill(self, names):
        """
        Plot a colorfill from the selected workspaces

        :param names: A list of workspace names
        """
        try:
            pcolormesh(self._ads.retrieveWorkspaces(names, unrollGroups=True))
        except BaseException:
            import traceback
            traceback.print_exc()
示例#4
0
    def _do_plot_colorfill(self, names):
        """
        Plot a colorfill from the selected workspaces

        :param names: A list of workspace names
        """
        try:
            pcolormesh(self._ads.retrieveWorkspaces(names, unrollGroups=True))
        except BaseException:
            import traceback
            traceback.print_exc()
示例#5
0
def plotForce(inWS, Plot):
    if Plot == 'Spectrum' or Plot == 'Both':
        nHist = mtd[inWS].getNumberHistograms()
        if nHist > 10:
            nHist = 10
        plot_list = []
        for i in range(0, nHist):
            plot_list.append(i)
        plotSpectrum(inWS, plot_list)
    if Plot == 'Contour' or Plot == 'Both':
        pcolormesh(inWS)
示例#6
0
    def _do_plot_colorfill(self, names):
        """
        Plot a colorfill from the selected workspaces

        :param names: A list of workspace names
        :param contour: An optional bool for whether to draw contour lines.
        """
        try:
            pcolormesh(names)
        except BaseException:
            import traceback
            traceback.print_exc()
示例#7
0
    def test_apply_properties_applies_to_all_images_if_multiple_colorfill_plots_and_one_colorbar(
            self):
        fig = pcolormesh([self.ws, self.ws])
        props = {
            'label': 'New Label',
            'colormap': 'jet',
            'vmin': 0,
            'vmax': 2,
            'scale': 'Linear',
            'interpolation': 'None'
        }
        if LooseVersion(matplotlib.__version__) > LooseVersion("3.1.3"):
            mock_view = Mock(
                get_selected_image_name=lambda: 'ws: (0, 0) - child0',
                get_properties=lambda: ImageProperties(props))
        else:
            mock_view = Mock(
                get_selected_image_name=lambda: 'ws: (0, 0) - image0',
                get_properties=lambda: ImageProperties(props))
        presenter = self._generate_presenter(fig=fig, view=mock_view)
        presenter.apply_properties()

        for ax in range(2):
            image = fig.axes[ax].images[0]

            if image.colorbar:
                self.assertEqual('New Label', image.colorbar.ax.get_ylabel())

            self.assertEqual('jet', image.cmap.name)
            self.assertEqual(0, image.norm.vmin)
            self.assertEqual(2, image.norm.vmax)
            self.assertTrue(isinstance(image.norm, Normalize))
def plot(plot_type: SpectraSelection, plot_index: int, axis_name: str,
         log_name: str, custom_log_values: List[float],
         workspaces: List[Workspace]) -> None:
    if len(workspaces) > 0:
        matrix_ws = _create_workspace_for_group_plot(plot_type, workspaces,
                                                     plot_index, log_name,
                                                     custom_log_values)

        workspace_names = [ws.name() for ws in workspaces]
        title = _construct_title(workspace_names, plot_index)

        if plot_type == SpectraSelection.Surface:
            fig, ax = plt.subplots(subplot_kw={'projection': 'mantid3d'})
            surface = ax.plot_surface(matrix_ws, cmap='viridis')

            ax.set_title("Surface" + title)
            ax.set_ylabel(axis_name)

            fig.canvas.set_window_title("Surface" + title)

            fig.colorbar(surface)

            fig.show()
        elif plot_type == SpectraSelection.Contour:
            fig = pcolormesh([matrix_ws])
            ax = fig.get_axes()[0]

            ax.contour(matrix_ws, levels=2, colors='k', linewidths=0.5)

            ax.set_ylabel(axis_name)
            ax.set_title("Contour" + title)

            fig.canvas.set_window_title("Contour" + title)
示例#9
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':
        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 mantidqt.plotting.functions import pcolormesh
        pcolormesh(workspace_name)
示例#10
0
    def test_toggle_normalisation_applies_to_all_images_if_one_colorbar(self):
        fig = pcolormesh([self.ws, self.ws])

        mock_canvas = MagicMock(figure=fig)
        fig_manager_mock = MagicMock(canvas=mock_canvas)
        fig_interactor = FigureInteraction(fig_manager_mock)

        # there should be 3 axes, 2 colorplots and 1 colorbar
        self.assertEqual(3, len(fig.axes))
        fig.axes[0].tracked_workspaces.values()
        self.assertTrue(fig.axes[0].tracked_workspaces['ws'][0].is_normalized)
        self.assertTrue(fig.axes[1].tracked_workspaces['ws'][0].is_normalized)

        fig_interactor._toggle_normalization(fig.axes[0])

        self.assertFalse(fig.axes[0].tracked_workspaces['ws'][0].is_normalized)
        self.assertFalse(fig.axes[1].tracked_workspaces['ws'][0].is_normalized)
示例#11
0
    def test_apply_properties_applies_to_all_images_if_mixed_colorfill_plots_and_one_colorbar(
            self):
        # self.ws does not have common bins and has evenly spaced values on spectrum axis (gives Image)
        # Also create ws with common bins, evenly spaced bin edges and uneven values on spectrum axis (gives QuadMesh)
        ws = CreateWorkspace(DataX=list([0, 1, 2, 3, 4]) * 4,
                             DataY=range(20),
                             NSpec=4,
                             OutputWorkspace='test_ws',
                             VerticalAxisUnit='TOF',
                             VerticalAxisValues=[1, 2, 4, 10])
        fig = pcolormesh([self.ws, ws])
        self.assertTrue(
            isinstance(fig.axes[0].images[0], matplotlib.image.AxesImage))
        self.assertTrue(
            isinstance(fig.axes[1].collections[0],
                       matplotlib.collections.QuadMesh))
        props = {
            'label': 'New Label',
            'colormap': 'jet',
            'vmin': 0,
            'vmax': 2,
            'scale': 'Linear',
            'interpolation': 'None'
        }
        if LooseVersion(matplotlib.__version__) > LooseVersion("3.1.3"):
            mock_view = Mock(
                get_selected_image_name=lambda: 'ws: (0, 0) - child0',
                get_properties=lambda: ImageProperties(props))
        else:
            mock_view = Mock(
                get_selected_image_name=lambda: 'ws: (0, 0) - image0',
                get_properties=lambda: ImageProperties(props))
        presenter = self._generate_presenter(fig=fig, view=mock_view)
        presenter.apply_properties()

        images = datafunctions.get_images_from_figure(fig)
        for image in images:
            if image.colorbar:
                self.assertEqual('New Label', image.colorbar.ax.get_ylabel())

            self.assertEqual('jet', image.cmap.name)
            self.assertEqual(0, image.norm.vmin)
            self.assertEqual(2, image.norm.vmax)
            self.assertTrue(isinstance(image.norm, Normalize))
示例#12
0
    def test_changes_apply_to_all_colorfill_plots_if_one_colorbar(self):
        ws = WorkspaceFactory.Instance().create("Workspace2D", NVectors=1, YLength=5, XLength=5)
        fig = pcolormesh([ws, ws])
        # there should be 3 axes: 2 colorfill plots and 1 colorbar
        self.assertEqual(3, len(fig.axes))

        colorbarEditor = ColorbarAxisEditor(fig.canvas, fig.axes[2])

        min_value = 1.0
        max_value = 2.0
        colorbarEditor.ui.editor_min.text = MagicMock(return_value=min_value)
        colorbarEditor.ui.editor_max.text = MagicMock(return_value=max_value)
        colorbarEditor.ui.logBox.isChecked = MagicMock(return_value=True)

        colorbarEditor.changes_accepted()

        for ax in range(2):
            self.assertEqual(min_value, fig.axes[ax].collections[0].norm.vmin)
            self.assertEqual(max_value, fig.axes[ax].collections[0].norm.vmax)
            self.assertTrue(isinstance(fig.axes[ax].collections[0].norm, LogNorm))
示例#13
0
def plotMuscat(inWS, spec_list, Plot):
    if Plot == 'Totals' or Plot == 'All':
        plotSpectrum(inWS + '_Totals', spec_list)
    if Plot == 'Scat1' or Plot == 'All':
        pcolormesh(inWS + '_1')