diff --git a/docs/source/release/v5.1.0/mantidworkbench.rst b/docs/source/release/v5.1.0/mantidworkbench.rst index ab08d04905b1de6065bfdd90b59de522938e6735..68b5a8cfedda5ed970aef8ec7ea6ee418acaa7b7 100644 --- a/docs/source/release/v5.1.0/mantidworkbench.rst +++ b/docs/source/release/v5.1.0/mantidworkbench.rst @@ -16,5 +16,6 @@ Bugfixes ######## - Fixed a bug where setting columns to Y error in table workspaces wasn't working. The links between the Y error and Y columns weren't being set up properly +- The scale of the color bars on colorfill plots of ragged workspaces now uses the maximum and minimum values of the data. :ref:`Release 5.1.0 <v5.1.0>` diff --git a/qt/applications/workbench/workbench/plotting/figureinteraction.py b/qt/applications/workbench/workbench/plotting/figureinteraction.py index a23811d34f04cf233a7fa7f2688fcbd637d5969d..e04c78b580afae3c4270048140681e317eb95615 100644 --- a/qt/applications/workbench/workbench/plotting/figureinteraction.py +++ b/qt/applications/workbench/workbench/plotting/figureinteraction.py @@ -12,6 +12,7 @@ Defines interaction behaviour for plotting. from __future__ import (absolute_import, unicode_literals) # std imports +import numpy as np from collections import OrderedDict from copy import copy from functools import partial @@ -704,6 +705,12 @@ class FigureInteraction(object): 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) diff --git a/qt/applications/workbench/workbench/plotting/test/test_figureinteraction.py b/qt/applications/workbench/workbench/plotting/test/test_figureinteraction.py index 3c54cd45f94d3a4ec4ad177f457df61893c06f03..a39ea453c058371eaf7d87ceb0c4b596ac693786 100644 --- a/qt/applications/workbench/workbench/plotting/test/test_figureinteraction.py +++ b/qt/applications/workbench/workbench/plotting/test/test_figureinteraction.py @@ -27,7 +27,7 @@ from mantid.plots import MantidAxes from mantid.py3compat.mock import MagicMock, PropertyMock, call, patch from mantid.simpleapi import CreateWorkspace from mantidqt.plotting.figuretype import FigureType -from mantidqt.plotting.functions import plot +from mantidqt.plotting.functions import plot, pcolormesh_from_names from mantidqt.utils.qt.testing import start_qapplication from workbench.plotting.figureinteraction import FigureInteraction @@ -378,6 +378,19 @@ class FigureInteractionTest(unittest.TestCase): current_scale_types2 = (ax.get_xscale(), ax.get_yscale()) self.assertNotEqual(current_scale_types2, current_scale_types1) + 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()) + # Private methods def _create_mock_fig_manager_to_accept_right_click(self): fig_manager = MagicMock() diff --git a/qt/python/mantidqt/plotting/functions.py b/qt/python/mantidqt/plotting/functions.py index 71f85df551006bfe6456286c24e026de33149de0..6be1029037a8bf881f643bf294399a838abbf916 100644 --- a/qt/python/mantidqt/plotting/functions.py +++ b/qt/python/mantidqt/plotting/functions.py @@ -162,6 +162,10 @@ def pcolormesh(workspaces, fig=None): if subplot_idx < workspaces_len: ws = workspaces[subplot_idx] pcm = pcolormesh_on_axis(ax, ws) + if pcm: # Colour bar limits are wrong if workspace is ragged. Set them manually. + colorbar_min = np.nanmin(pcm.get_array()) + colorbar_max = np.nanmax(pcm.get_array()) + pcm.set_clim(colorbar_min, colorbar_max) if col_idx < ncols - 1: col_idx += 1 else: diff --git a/qt/python/mantidqt/plotting/test/test_functions.py b/qt/python/mantidqt/plotting/test/test_functions.py index 6dcd7c66a005a2b2c6bb62b31eed3ea5d26e949c..1d88e593e042e8da65c1e8e70974dececc9cba3f 100644 --- a/qt/python/mantidqt/plotting/test/test_functions.py +++ b/qt/python/mantidqt/plotting/test/test_functions.py @@ -23,6 +23,7 @@ import numpy as np # register mantid projection import mantid.plots # noqa from mantid.api import AnalysisDataService, WorkspaceFactory +from mantid.simpleapi import CreateWorkspace from mantid.kernel import config from mantid.plots import MantidAxes from mantid.py3compat import mock @@ -151,6 +152,11 @@ class FunctionsTest(TestCase): pcolormesh_from_names([ws_name]) self.assertEqual(1, pcolormesh_mock.call_count) + 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(self): ws_name = 'test_pcolormesh_from_names-1' AnalysisDataService.Instance().addOrReplace(ws_name, self._test_ws)