コード例 #1
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()
コード例 #2
0
ファイル: functions.py プロジェクト: robertapplin/mantid
def pcolormesh(workspaces,
               fig=None,
               color_norm=None,
               normalize_by_bin_width=None):
    """
    Create a figure containing pcolor subplots

    :param workspaces: A list of workspace handles
    :param fig: An optional figure to contain the new plots. Its current contents will be cleared
    :param normalize_by_bin_width: Optional and only to be used in the event that the function is being called as part
    of a plot restore
    :returns: The figure containing the plots
    """
    # check inputs
    _validate_pcolormesh_inputs(workspaces)
    workspaces = [ws for ws in workspaces if isinstance(ws, MatrixWorkspace)]

    # create a subplot of the appropriate number of dimensions
    # extend in number of columns if the number of plottables is not a square number
    workspaces_len = len(workspaces)
    fig, axes, nrows, ncols = create_subplots(workspaces_len, fig=fig)

    plots = []
    row_idx, col_idx = 0, 0
    for subplot_idx in range(nrows * ncols):
        ax = axes[row_idx][col_idx]
        if subplot_idx < workspaces_len:
            ws = workspaces[subplot_idx]
            pcm = pcolormesh_on_axis(ax, ws, color_norm,
                                     normalize_by_bin_width)
            plots.append(pcm)
            if col_idx < ncols - 1:
                col_idx += 1
            else:
                row_idx += 1
                col_idx = 0

            if ConfigService.getString("plots.ShowMinorTicks").lower() == "on":
                ax.minorticks_on()

            ax.show_minor_gridlines = ConfigService.getString(
                "plots.ShowMinorGridlines").lower() == "on"
        else:
            # nothing here
            ax.axis('off')

    # If there are multiple plots limits are the min and max of all the plots
    colorbar_min = min(pt.norm.vmin for pt in plots)
    colorbar_max = max(pt.norm.vmax for pt in plots)
    for pt in plots:
        pt.set_clim(colorbar_min, colorbar_max)

    # Adjust locations to ensure the plots don't overlap
    fig.subplots_adjust(wspace=SUBPLOT_WSPACE, hspace=SUBPLOT_HSPACE)

    axes = axes.ravel()
    colorbar = fig.colorbar(pcm, ax=axes.tolist(), pad=0.06)
    add_colorbar_label(colorbar, axes)

    if fig.canvas.manager is not None:
        fig.canvas.manager.set_window_title(
            figure_title(workspaces, fig.number))
    # assert a minimum size, otherwise we can lose axis labels
    size = fig.get_size_inches()
    if (size[0] <= COLORPLOT_MIN_WIDTH) or (size[1] <= COLORPLOT_MIN_HEIGHT):
        fig.set_size_inches(COLORPLOT_MIN_WIDTH,
                            COLORPLOT_MIN_HEIGHT,
                            forward=True)
    fig.canvas.draw()
    fig.show()
    return fig