def test_pcolormesh_from_names_using_existing_figure(self): ws_name = 'test_pcolormesh_from_names-1' AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws) target_fig = plt.figure() fig = pcolormesh_from_names([ws_name], fig=target_fig) self.assertEqual(fig, target_fig) self.assertEqual(1, len(fig.gca().images))
def test_pcolormesh_from_names_with_non_plottable_workspaces_returns_None( self): table = WorkspaceFactory.Instance().createTable() table_name = 'test_pcolormesh_from_names_with_non_plottable_workspaces_returns_None' AnalysisDataService.Instance().addOrReplace(table_name, table) result = pcolormesh_from_names([table_name]) self.assertEqual(result, None)
def test_pcolor_mesh_from_names_gets_colorbar_scale_from_ConfigService(self, mock_ConfigService): ws = CreateSampleWorkspace() fig = pcolormesh_from_names([ws]) mock_ConfigService.getString.assert_any_call('plots.images.ColorBarScale') self.assertTrue(isinstance(fig.gca().images[0].colorbar.norm, matplotlib.colors.LogNorm))
def test_pcolor_mesh_from_names_gets_colormap_from_ConfigService(self, mock_ConfigService): ws = CreateSampleWorkspace() spring_colormap = cm.get_cmap('spring') fig = pcolormesh_from_names([ws]) mock_ConfigService.getString.assert_any_call('plots.images.Colormap') self.assertEqual(fig.gca().images[0].colorbar.get_cmap(), spring_colormap)
def test_log_maintained_when_normalisation_toggled(self): ws = CreateWorkspace(DataX=[1, 2, 3, 4, 2, 4, 6, 8], DataY=[2] * 8, NSpec=2, OutputWorkspace="ragged_ws") fig = pcolormesh_from_names([ws]) mock_canvas = MagicMock(figure=fig) fig_manager_mock = MagicMock(canvas=mock_canvas) fig_interactor = FigureInteraction(fig_manager_mock) fig_interactor._change_colorbar_axes(LogNorm) fig_interactor._toggle_normalization(fig.axes[0]) self.assertTrue(isinstance(fig.axes[0].images[-1].norm, LogNorm))
def test_scale_on_ragged_workspaces_maintained_when_toggling_normalisation(self): ws = CreateWorkspace(DataX=[1, 2, 3, 4, 2, 4, 6, 8], DataY=[2] * 8, NSpec=2, OutputWorkspace="ragged_ws") fig = pcolormesh_from_names([ws]) mock_canvas = MagicMock(figure=fig) fig_manager_mock = MagicMock(canvas=mock_canvas) fig_interactor = FigureInteraction(fig_manager_mock) fig_interactor._toggle_normalization(fig.axes[0]) clim = fig.axes[0].images[0].get_clim() fig_interactor._toggle_normalization(fig.axes[0]) self.assertEqual(clim, fig.axes[0].images[0].get_clim()) self.assertNotEqual((-0.1, 0.1), fig.axes[0].images[0].get_clim())
def _plot_on_here(self, names): """ 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 """ if len(names) == 0: return # local import to avoid circular import with FigureManager from mantidqt.plotting.functions import pcolormesh_from_names, plot_from_names fig = self._canvas.figure fig_type = figure_type(fig) if fig_type == FigureType.Image: pcolormesh_from_names(names, fig=fig) else: plot_from_names(names, errors=(fig_type == FigureType.Errorbar), overplot=True, fig=fig)
def test_pcolormesh_from_names(self): ws_name = 'test_pcolormesh_from_names-1' AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws) fig = pcolormesh_from_names([ws_name]) self.assertEqual(1, len(fig.gca().images))
def test_scale_is_correct_on_pcolourmesh_of_ragged_workspace(self): ws = CreateWorkspace(DataX=[1, 2, 3, 4, 2, 4, 6, 8], DataY=[2] * 8, NSpec=2) fig = pcolormesh_from_names([ws]) self.assertEqual((1.8, 2.2), fig.axes[0].images[0].get_clim())
def test_pcolormesh_from_names_calls_pcolormesh(self, pcolormesh_mock): ws_name = 'test_pcolormesh_from_names_calls_pcolormesh-1' AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws) pcolormesh_from_names([ws_name]) self.assertEqual(1, pcolormesh_mock.call_count)
def test_pcolormesh_from_names_with_non_plottable_workspaces_returns_None(self): table = WorkspaceFactory.Instance().createTable() table_name = 'test_pcolormesh_from_names_with_non_plottable_workspaces_returns_None' AnalysisDataService.Instance().addOrReplace(table_name, table) result = pcolormesh_from_names([table_name]) self.assertTrue(result is None)