From 9fc1a72098d9ad35b7a1cfdc81d7d06b7ef05b3e Mon Sep 17 00:00:00 2001
From: Phil Colebrooke <philipc99@hotmail.co.uk>
Date: Thu, 5 Mar 2020 10:51:36 +0000
Subject: [PATCH] Re #28226 add check for negative min/max values + release
 notes

---
 .../PythonInterface/mantid/plots/datafunctions.py    |  8 ++++++--
 docs/source/release/v5.0.0/mantidworkbench.rst       |  1 +
 .../plotconfigdialog/imagestabwidget/presenter.py    |  4 ++++
 .../widgets/plotconfigdialog/imagestabwidget/view.py | 12 +++++++++---
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/Framework/PythonInterface/mantid/plots/datafunctions.py b/Framework/PythonInterface/mantid/plots/datafunctions.py
index 74ddac5e5a0..24a0ed26dc9 100644
--- a/Framework/PythonInterface/mantid/plots/datafunctions.py
+++ b/Framework/PythonInterface/mantid/plots/datafunctions.py
@@ -1013,8 +1013,12 @@ def update_colorbar_scale(figure, image, scale, vmin, vmax):
     :param vmin: the minimum value on the colorbar
     :param vmax: the maximum value on the colorbar
     """
-    if vmin == 0 and scale == LogNorm:
-        vmin += 1e-6  # Avoid 0 log scale error
+    if vmin <= 0 and scale == LogNorm:
+        vmin = 1e-6  # Avoid 0 log scale error
+
+    if vmax <= 0 and scale == LogNorm:
+        vmax = 1  # Avoid 0 log scale error
+
     image.set_norm(scale(vmin=vmin, vmax=vmax))
     if image.colorbar:
         image.colorbar.remove()
diff --git a/docs/source/release/v5.0.0/mantidworkbench.rst b/docs/source/release/v5.0.0/mantidworkbench.rst
index d7a70fb523c..c34f669dbc0 100644
--- a/docs/source/release/v5.0.0/mantidworkbench.rst
+++ b/docs/source/release/v5.0.0/mantidworkbench.rst
@@ -114,5 +114,6 @@ Bugfixes
 - Fixed bug that caused an error if a MDHistoWorkspace was plotted and a user attempted to open a context menu.
 - Fixed a bug which caused graphic scaling issues when the double-click menu was used to set an axis as log-scaled.
 - Fixed a bug where the colorbar in the instrument view would sometimes have no markers if the scale was set to SymmetricLog10.
+- Fixed an unhandled exception when you set the min or max value of the colorbar scale in a colorfill plot to negative when the scale is set to logarithmic.
 
 :ref:`Release 5.0.0 <v5.0.0>`
diff --git a/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/presenter.py b/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/presenter.py
index 1ed80b8cd2e..bc595818075 100644
--- a/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/presenter.py
+++ b/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/presenter.py
@@ -30,6 +30,7 @@ class ImagesTabWidgetPresenter:
         # Signals
         self.view.select_image_combo_box.currentIndexChanged.connect(
             self.update_view)
+        self.view.scale_combo_box.currentTextChanged.connect(self.scale_changed)
 
     def apply_properties(self):
         props = self.view.get_properties()
@@ -112,3 +113,6 @@ class ImagesTabWidgetPresenter:
                 self.generate_image_name(img), img, self.image_names_dict)
         self.view.populate_select_image_combo_box(
             sorted(self.image_names_dict.keys()))
+
+    def scale_changed(self, scale):
+        self.view.set_min_max_ranges(scale)
diff --git a/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/view.py b/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/view.py
index d92f22869cb..a4ddc4c00eb 100644
--- a/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/view.py
+++ b/qt/python/mantidqt/widgets/plotconfigdialog/imagestabwidget/view.py
@@ -42,12 +42,18 @@ class ImagesTabWidgetView(QWidget):
         self._populate_interpolation_combo_box()
         self._populate_scale_combo_box()
 
+        self.set_min_max_ranges(self.get_scale())
+
+        self.max_min_value_warning.setVisible(False)
+
+    def set_min_max_ranges(self, scale):
         # Set maximum and minimum for the min/max spin boxes
         for bound in ['min', 'max']:
             spin_box = getattr(self, '%s_value_spin_box' % bound)
-            spin_box.setRange(0, np.finfo(np.float32).max)
-
-        self.max_min_value_warning.setVisible(False)
+            if scale == "Linear":
+                spin_box.setRange(np.finfo(np.float32).min, np.finfo(np.float32).max)
+            else:
+                spin_box.setRange(0, np.finfo(np.float32).max)
 
     def _populate_colormap_combo_box(self):
         for cmap_name in get_colormap_names():
-- 
GitLab