diff --git a/Framework/PythonInterface/mantid/plots/axesfunctions.py b/Framework/PythonInterface/mantid/plots/axesfunctions.py index 7714bcec5a9a..dc03f17585ec 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 = 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 = 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) 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) 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