From 6d9180e5dd974f033c2f9f4daff3ae8267412152 Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Mon, 16 Sep 2024 16:47:47 +0100 Subject: [PATCH 1/4] add check for negative errors, convert to positive --- Framework/PythonInterface/mantid/plots/axesfunctions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Framework/PythonInterface/mantid/plots/axesfunctions.py b/Framework/PythonInterface/mantid/plots/axesfunctions.py index 7714bcec5a9a..45f4a94ed374 100644 --- a/Framework/PythonInterface/mantid/plots/axesfunctions.py +++ b/Framework/PythonInterface/mantid/plots/axesfunctions.py @@ -41,6 +41,7 @@ ) from mantid.plots.utility import MantidAxType from mantid.plots.quad_mesh_wrapper import QuadMeshWrapper +from mantid import logger # Used for initializing searches of max, min values _LARGEST, _SMALLEST = float(sys.maxsize), -sys.maxsize @@ -286,6 +287,14 @@ def errorbar(axes, workspace, *args, **kwargs): _setLabels1D(axes, workspace, indices, normalize_by_bin_width=normalize_by_bin_width, axis=axis) kwargs.pop("normalize_by_bin_width", None) + if dy is not None and min(dy) < 0: + dy = abs(dy) + logger.warning("Negative values found in y error when plotting error bars. Converting to positive and continuing.") + + if dx is not None and min(dx) < 0: + dx = abs(dx) + logger.warning("Negative values found in x error when plotting error bars. Converting to positive and continuing.") + return axes.errorbar(x, y, dy, dx, *args, **kwargs) From dc23b3ccfaebe93bcf1015b21f15dd22c574e283 Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Tue, 17 Sep 2024 09:58:10 +0100 Subject: [PATCH 2/4] add simple test --- .../test/python/mantid/plots/axesfunctionsTest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Framework/PythonInterface/test/python/mantid/plots/axesfunctionsTest.py b/Framework/PythonInterface/test/python/mantid/plots/axesfunctionsTest.py index d9c6bfad2cca..740353633dcf 100644 --- a/Framework/PythonInterface/test/python/mantid/plots/axesfunctionsTest.py +++ b/Framework/PythonInterface/test/python/mantid/plots/axesfunctionsTest.py @@ -45,6 +45,12 @@ def setUpClass(cls): VerticalAxisValues=[4, 6, 8], OutputWorkspace="ws2d_histo", ) + cls.ws2d_histo_negative_errors = CreateWorkspace( + DataX=[1, 2, 3, 4], + DataY=[10, 20, 30, 40], + DataE=[1, -2, 3, -4], + OutputWorkspace="ws2d_histo_negative_errors" + ) cls.ws2d_histo_non_dist = CreateWorkspace( DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], @@ -151,6 +157,10 @@ def test_1d_errorbars(self): funcs.errorbar(ax, self.ws2d_histo, specNum=2, linewidth=6) funcs.errorbar(ax, self.ws_MD_1d, "bo") + def test_1d_errorbars_with_negative_errors(self): + _, ax = plt.subplots() + funcs.errorbar(ax, self.ws2d_histo_negative_errors, specNum=1) + def test_1d_scatter(self): fig, ax = plt.subplots() funcs.scatter(ax, self.ws2d_histo, specNum=1) From f1bb99f3d1cb2ca9059bd64805212109828a88c9 Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Tue, 17 Sep 2024 10:56:25 +0100 Subject: [PATCH 3/4] add release note --- docs/source/release/v6.11.0/Workbench/Bugfixes/37973.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/source/release/v6.11.0/Workbench/Bugfixes/37973.rst diff --git a/docs/source/release/v6.11.0/Workbench/Bugfixes/37973.rst b/docs/source/release/v6.11.0/Workbench/Bugfixes/37973.rst new file mode 100644 index 000000000000..feb2e88fc0e6 --- /dev/null +++ b/docs/source/release/v6.11.0/Workbench/Bugfixes/37973.rst @@ -0,0 +1 @@ +- Fixed crash when attempting to plot data with negative error values. \ No newline at end of file From 67752003a3e9f0a8aa9716910bd07a1a9576a8c2 Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Fri, 27 Sep 2024 14:14:47 +0100 Subject: [PATCH 4/4] set errors to none if negative instead --- Framework/PythonInterface/mantid/plots/axesfunctions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Framework/PythonInterface/mantid/plots/axesfunctions.py b/Framework/PythonInterface/mantid/plots/axesfunctions.py index 45f4a94ed374..dc03f17585ec 100644 --- a/Framework/PythonInterface/mantid/plots/axesfunctions.py +++ b/Framework/PythonInterface/mantid/plots/axesfunctions.py @@ -288,12 +288,12 @@ def errorbar(axes, workspace, *args, **kwargs): kwargs.pop("normalize_by_bin_width", None) if dy is not None and min(dy) < 0: - dy = abs(dy) - logger.warning("Negative values found in y error when plotting error bars. Converting to positive and continuing.") + dy = None + logger.warning("Negative values found in y error when plotting error bars. Continuing without y error bars.") if dx is not None and min(dx) < 0: - dx = abs(dx) - logger.warning("Negative values found in x error when plotting error bars. Converting to positive and continuing.") + dx = None + logger.warning("Negative values found in x error when plotting error bars. Continuing without x error bars.") return axes.errorbar(x, y, dy, dx, *args, **kwargs)