Exemplo n.º 1
0
    def waterfall_reverse_line_order(self):
        ax = self.canvas.figure.get_axes()[0]
        x, y = ax.waterfall_x_offset, ax.waterfall_y_offset
        fills = datafunctions.get_waterfall_fills(ax)
        ax.update_waterfall(0, 0)

        errorbar_cap_lines = datafunctions.remove_and_return_errorbar_cap_lines(
            ax)

        ax.lines.reverse()
        for cap in errorbar_cap_lines:
            ax.add_line(cap)
        if LooseVersion("3.7") > LooseVersion(
                matplotlib.__version__) >= LooseVersion("3.2"):
            for line_fill in fills:
                if line_fill not in ax.collections:
                    ax.add_collection(line_fill)
        elif LooseVersion(matplotlib.__version__) < LooseVersion("3.2"):
            ax.collections += fills
        else:
            raise NotImplementedError(
                "ArtistList will become an immutable tuple in matplotlib 3.7 and thus, "
                "this code doesn't work anymore.")
        ax.collections.reverse()
        ax.update_waterfall(x, y)

        if ax.get_legend():
            ax.make_legend()

        self.canvas.draw()
Exemplo n.º 2
0
    def _toggle_normalization(self, selected_ax):
        if figure_type(self.canvas.figure) == FigureType.Image and len(self.canvas.figure.get_axes()) > 1:
            axes = datafunctions.get_axes_from_figure(self.canvas.figure)
        else:
            axes = [selected_ax]

        for ax in axes:
            waterfall = isinstance(ax, MantidAxes) and ax.is_waterfall()
            if waterfall:
                x, y = ax.waterfall_x_offset, ax.waterfall_y_offset
                has_fill = ax.waterfall_has_fill()

                if has_fill:
                    line_colour_fill = datafunctions.waterfall_fill_is_line_colour(ax)
                    if line_colour_fill:
                        fill_colour = None
                    else:
                        fill_colour = datafunctions.get_waterfall_fills(ax)[0].get_facecolor()

                ax.update_waterfall(0, 0)

            # The colorbar can get screwed up with ragged workspaces and log scales as they go
            # through the normalisation toggle.
            # Set it to Linear and change it back after if necessary, since there's no reason
            # to duplicate the handling.
            colorbar_log = False
            if ax.images:
                colorbar_log = isinstance(ax.images[-1].norm, LogNorm)
                if colorbar_log:
                    self._change_colorbar_axes(Normalize)

            self._change_plot_normalization(ax)

            if ax.lines:  # Relim causes issues with colour plots, which have no lines.
                ax.relim()
                ax.autoscale()

            if ax.images:  # Colour bar limits are wrong if workspace is ragged. Set them manually.
                colorbar_min = np.nanmin(ax.images[-1].get_array())
                colorbar_max = np.nanmax(ax.images[-1].get_array())
                for image in ax.images:
                    image.set_clim(colorbar_min, colorbar_max)

                    # Update the colorbar label
                    cb = image.colorbar
                    if cb:
                        datafunctions.add_colorbar_label(cb, ax.get_figure().axes)
                if colorbar_log:  # If it had a log scaled colorbar before, put it back.
                    self._change_colorbar_axes(LogNorm)

                axesfunctions.update_colorplot_datalimits(ax, ax.images)

            datafunctions.set_initial_dimensions(ax)
            if waterfall:
                ax.update_waterfall(x, y)

                if has_fill:
                    ax.set_waterfall_fill(True, fill_colour)

        self.canvas.draw()
Exemplo n.º 3
0
    def _toggle_normalization(self, ax):
        waterfall = isinstance(ax, MantidAxes) and ax.is_waterfall()
        if waterfall:
            x, y = ax.waterfall_x_offset, ax.waterfall_y_offset
            has_fill = ax.waterfall_has_fill()

            if has_fill:
                line_colour_fill = datafunctions.waterfall_fill_is_line_colour(ax)
                if line_colour_fill:
                    fill_colour = None
                else:
                    fill_colour = datafunctions.get_waterfall_fills(ax)[0].get_facecolor()

            ax.update_waterfall(0, 0)

        is_normalized = self._is_normalized(ax)
        for arg_set in ax.creation_args:
            if arg_set['workspaces'] in ax.tracked_workspaces:
                workspace = ads.retrieve(arg_set['workspaces'])
                arg_set['distribution'] = is_normalized
                arg_set_copy = copy(arg_set)
                [
                    arg_set_copy.pop(key)
                    for key in ['function', 'workspaces', 'autoscale_on_update', 'norm']
                    if key in arg_set_copy.keys()
                ]
                if 'specNum' not in arg_set:
                    if 'wkspIndex' in arg_set:
                        arg_set['specNum'] = workspace.getSpectrum(
                            arg_set.pop('wkspIndex')).getSpectrumNo()
                    else:
                        raise RuntimeError("No spectrum number associated with plot of "
                                           "workspace '{}'".format(workspace.name()))
                # 2D plots have no spec number so remove it
                if figure_type(self.canvas.figure) == FigureType.Image:
                    arg_set_copy.pop('specNum')
                for ws_artist in ax.tracked_workspaces[workspace.name()]:
                    if ws_artist.spec_num == arg_set.get('specNum'):
                        ws_artist.is_normalized = not is_normalized
                        ws_artist.replace_data(workspace, arg_set_copy)
        if ax.lines:  # Relim causes issues with colour plots, which have no lines.
            ax.relim()

        if ax.images:  # Colour bar limits are wrong if workspace is ragged. Set them manually.
            colorbar_min = np.nanmin(ax.images[-1].get_array())
            colorbar_max = np.nanmax(ax.images[-1].get_array())
            for image in ax.images:
                image.set_clim(colorbar_min, colorbar_max)

        ax.autoscale()

        datafunctions.set_initial_dimensions(ax)
        if waterfall:
            ax.update_waterfall(x, y)

            if has_fill:
                ax.set_waterfall_fill(True, fill_colour)

        self.canvas.draw()
Exemplo n.º 4
0
    def test_create_fill_creates_fills_for_waterfall_plot(self):
        fig, ax = plt.subplots(subplot_kw={'projection': 'mantid'})
        ax.plot([0, 1], [0, 1])
        ax.plot([0, 1], [0, 1])

        # Make a waterfall plot.
        ax.set_waterfall(True)
        # Add filled areas.
        ax.set_waterfall_fill(True)

        fills = datafunctions.get_waterfall_fills(ax)
        self.assertEqual(len(fills), 2)
Exemplo n.º 5
0
    def test_fills_not_created_if_waterfall_plot_already_has_filled_areas(self):
        fig, ax = plt.subplots(subplot_kw={'projection': 'mantid'})
        ax.plot([0, 1], [0, 1])
        ax.plot([0, 1], [0, 1])

        # Make a waterfall plot
        ax.set_waterfall(True)

        # Add filled areas twice
        ax.set_waterfall_fill(True)
        ax.set_waterfall_fill(True)

        # There should still be only two filled areas (one for each line)
        self.assertEqual(len(datafunctions.get_waterfall_fills(ax)), 2)
Exemplo n.º 6
0
    def waterfall_reverse_line_order(self):
        ax = self.canvas.figure.get_axes()[0]
        x, y = ax.waterfall_x_offset, ax.waterfall_y_offset
        fills = datafunctions.get_waterfall_fills(ax)
        ax.update_waterfall(0, 0)

        errorbar_cap_lines = datafunctions.remove_and_return_errorbar_cap_lines(ax)

        ax.lines.reverse()
        ax.lines += errorbar_cap_lines
        ax.collections += fills
        ax.collections.reverse()
        ax.update_waterfall(x, y)

        if ax.get_legend():
            ax.make_legend()