Skip to content

Commit f2d3ef9

Browse files
Merge release-next into main
2 parents 32b1971 + 7f66679 commit f2d3ef9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Framework/PythonInterface/mantid/plots/axesfunctions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
)
4242
from mantid.plots.utility import MantidAxType
4343
from mantid.plots.quad_mesh_wrapper import QuadMeshWrapper
44+
from mantid import logger
4445

4546
# Used for initializing searches of max, min values
4647
_LARGEST, _SMALLEST = float(sys.maxsize), -sys.maxsize
@@ -286,6 +287,14 @@ def errorbar(axes, workspace, *args, **kwargs):
286287
_setLabels1D(axes, workspace, indices, normalize_by_bin_width=normalize_by_bin_width, axis=axis)
287288
kwargs.pop("normalize_by_bin_width", None)
288289

290+
if dy is not None and min(dy) < 0:
291+
dy = None
292+
logger.warning("Negative values found in y error when plotting error bars. Continuing without y error bars.")
293+
294+
if dx is not None and min(dx) < 0:
295+
dx = None
296+
logger.warning("Negative values found in x error when plotting error bars. Continuing without x error bars.")
297+
289298
return axes.errorbar(x, y, dy, dx, *args, **kwargs)
290299

291300

Framework/PythonInterface/test/python/mantid/plots/axesfunctionsTest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ def setUpClass(cls):
4545
VerticalAxisValues=[4, 6, 8],
4646
OutputWorkspace="ws2d_histo",
4747
)
48+
cls.ws2d_histo_negative_errors = CreateWorkspace(
49+
DataX=[1, 2, 3, 4],
50+
DataY=[10, 20, 30, 40],
51+
DataE=[1, -2, 3, -4],
52+
OutputWorkspace="ws2d_histo_negative_errors"
53+
)
4854
cls.ws2d_histo_non_dist = CreateWorkspace(
4955
DataX=[10, 20, 30, 10, 20, 30],
5056
DataY=[2, 3, 4, 5],
@@ -151,6 +157,10 @@ def test_1d_errorbars(self):
151157
funcs.errorbar(ax, self.ws2d_histo, specNum=2, linewidth=6)
152158
funcs.errorbar(ax, self.ws_MD_1d, "bo")
153159

160+
def test_1d_errorbars_with_negative_errors(self):
161+
_, ax = plt.subplots()
162+
funcs.errorbar(ax, self.ws2d_histo_negative_errors, specNum=1)
163+
154164
def test_1d_scatter(self):
155165
fig, ax = plt.subplots()
156166
funcs.scatter(ax, self.ws2d_histo, specNum=1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed crash when attempting to plot data with negative error values.

0 commit comments

Comments
 (0)