Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Framework/PythonInterface/mantid/plots/axesfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/source/release/v6.11.0/Workbench/Bugfixes/37973.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed crash when attempting to plot data with negative error values.
Loading