Esempio n. 1
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 setUpClass(cls):
        # Mock axes tab view
        mock_axes_view = Mock(
            get_selected_ax_name=lambda: '(0, 0)',
            get_properties=lambda: AxProperties(new_ax_view_props))
        cls.ax_view_patch = patch(AX_VIEW, lambda x: mock_axes_view)
        cls.ax_view_mock = cls.ax_view_patch.start()

        # Mock curves tab view
        cls.curve_view_mock = Mock(
            get_selected_curve_name=lambda: 'old label',
            get_selected_ax_name=lambda: '(0, 0)',
            get_properties=lambda: CurveProperties(new_curve_view_props))
        cls.curve_view_patch = patch(CURVE_VIEW, lambda x: cls.curve_view_mock)
        cls.curve_view_patch.start()

        cls.ax = _run_apply_properties_on_figure_with_curve()
        cls.new_curve = cls.ax.containers[0]

        # Mock images tab view
        cls.img_view_mock = Mock(
            get_selected_image_name=lambda: '(0, 0) - old label',
            get_properties=lambda: ImageProperties(new_image_props))
        cls.img_view_patch = patch(IMAGE_VIEW, lambda x: cls.img_view_mock)
        cls.img_view_patch.start()

        cls.img_ax = _run_apply_properties_on_figure_with_image()
        cls.new_img = cls.img_ax.images[0]
Esempio n. 3
0
    def setUpClass(cls):
        # Mock axes tab view
        mock_axes_view = Mock(
            get_selected_ax_name=lambda: '(0, 0)',
            get_properties=lambda: AxProperties(new_ax_view_props))
        cls.ax_view_patch = patch(AX_VIEW, lambda x: mock_axes_view)
        cls.ax_view_mock = cls.ax_view_patch.start()

        # Mock curves tab view
        cls.curve_view_mock = Mock(
            get_selected_ax_name=lambda: '(0, 0)',
            select_curve_list=Mock(selectedItems=lambda: []),
            get_properties=lambda: CurveProperties(new_curve_view_props))
        cls.curve_view_patch = patch(CURVE_VIEW, lambda x: cls.curve_view_mock)
        cls.curve_view_patch.start()

        cls.ax = _run_apply_properties_on_figure_with_curve(
            cls.curve_view_mock)
        cls.new_curve = cls.ax.containers[0]

        # Mock images tab view
        if LooseVersion(matplotlib.__version__) > LooseVersion("3.1.3"):
            cls.img_view_mock = Mock(
                get_selected_image_name=lambda: '(0, 0) - child0',
                get_properties=lambda: ImageProperties(new_image_props))
        else:
            cls.img_view_mock = Mock(
                get_selected_image_name=lambda: '(0, 0) - image0',
                get_properties=lambda: ImageProperties(new_image_props))
        cls.img_view_patch = patch(IMAGE_VIEW, lambda x: cls.img_view_mock)
        cls.img_view_patch.start()

        cls.img_ax = _run_apply_properties_on_figure_with_image()
        cls.new_img = cls.img_ax.images[0]

        # Mock legend tab view
        cls.legend_view_mock = Mock(
            get_properties=lambda: LegendProperties(new_legend_props))
        cls.legend_view_patch = patch(LEGEND_VIEW,
                                      lambda x: cls.legend_view_mock)
        cls.legend_view_patch.start()

        cls.legend_ax = _run_apply_properties_on_figure_with_legend(
            cls.curve_view_mock)
        cls.new_legend = cls.legend_ax.get_legend()
Esempio n. 4
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))
Esempio n. 5
0
 def update_view(self):
     # self.view.update(ImageProperties.from_image(self.get_selected_image()))
     img_props = ImageProperties.from_image(self.get_selected_image())
     self.view.set_label(img_props.label)
     self.view.set_colormap(img_props.colormap)
     self.view.set_min_value(img_props.vmin)
     self.view.set_max_value(img_props.vmax)
     if img_props.interpolation:
         self.view.enable_interpolation(True)
         self.view.set_interpolation(img_props.interpolation)
     else:
         self.view.set_interpolation('None')
         self.view.enable_interpolation(False)
     self.view.set_scale(img_props.scale)
Esempio n. 6
0
 def update_view(self):
     img_props = ImageProperties.from_image(self.get_selected_image())
     self.view.label_line_edit.setEnabled(bool(get_colorbars_from_fig(self.fig)))
     self.view.set_label(img_props.label)
     self.view.set_colormap(img_props.colormap)
     self.view.set_reverse_colormap(img_props.reverse_colormap)
     self.view.set_min_value(img_props.vmin)
     self.view.set_max_value(img_props.vmax)
     if img_props.interpolation:
         self.view.enable_interpolation(True)
         self.view.set_interpolation(img_props.interpolation)
     else:
         self.view.set_interpolation('None')
         self.view.enable_interpolation(False)
     self.view.set_scale(img_props.scale)
 def test_apply_properties_log_scale_with_zero_vmin(self):
     fig = figure()
     ax = fig.add_subplot(111)
     img = ax.imshow([[0, 2], [2, 0]], label='img label')
     props = {'title': '(0, 0) - img label',
              'label': 'New Label',
              'colormap': 'jet',
              'vmin': 0,
              'vmax': 4,
              'scale': 'Logarithmic',
              'interpolation': 'Hanning'}
     mock_view = Mock(get_selected_image_name=lambda: '(0, 0) - img label',
                      get_properties=lambda: ImageProperties(props))
     presenter = self._generate_presenter(fig=fig, view=mock_view)
     presenter.apply_properties()
     self.assertEqual("New Label", img.get_label())
     self.assertEqual('jet', img.cmap.name)
     self.assertEqual(1e-6, img.norm.vmin)
     self.assertEqual(4, img.norm.vmax)
     self.assertTrue(isinstance(img.norm, LogNorm))
 def test_apply_properties_sets_properties(self):
     fig = figure()
     ax = fig.add_subplot(111)
     img = ax.imshow([[0, 2], [2, 0]], label='img label')
     props = {'title': '(0, 0) - img label',
              'label': 'New Label',
              'colormap': 'jet',
              'vmin': 0,
              'vmax': 2,
              'scale': 'Linear',
              'interpolation': 'None'}
     mock_view = Mock(get_selected_image_name=lambda: '(0, 0) - img label',
                      get_properties=lambda: ImageProperties(props))
     presenter = self._generate_presenter(fig=fig, view=mock_view)
     presenter.apply_properties()
     self.assertEqual("New Label", img.get_label())
     self.assertEqual('jet', img.cmap.name)
     self.assertEqual(0, img.norm.vmin)
     self.assertEqual(2, img.norm.vmax)
     self.assertTrue(isinstance(img.norm, Normalize))
Esempio n. 9
0
 def get_properties(self):
     return ImageProperties.from_view(self)