示例#1
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))
示例#2
0
    def __init__(self, canvas, axes):
        super(ColorbarAxisEditor, self).__init__(canvas, axes, 'y')

        self.ui.gridBox.hide()

        self.images = []

        images = get_images_from_figure(canvas.figure)
        # If there are an equal number of plots and colorbars so apply changes to plot with the selected colorbar
        # Otherwise apply changes to all the plots in the figure
        if len(images) != len(self.canvas.figure.axes) / 2:
            self.images = images
        else:
            # apply changes to selected axes
            for img in images:
                if img.colorbar and img.colorbar.ax == axes:
                    self.images.append(img)

        self.create_model()
        self.ui.editor_format.setEnabled(False)