Skip to content

Commit f2c9bac

Browse files
committed
Robustness on the colorbar
1 parent c1fbbbd commit f2c9bac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/silx/gui/plot/ColorBar.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,10 @@ def mouseMoveEvent(self, event):
595595
def _getRelativePosition(self, yPixel):
596596
"""yPixel : pixel position into _ColorScale widget reference"""
597597
# widgets are bottom-top referencial but we display in top-bottom referential
598-
return 1.0 - (yPixel - self.margin) / float(self.height() - 2 * self.margin)
598+
height = float(self.height() - 2 * self.margin)
599+
if height == 0:
600+
return 0.0
601+
return 1.0 - (yPixel - self.margin) / height
599602

600603
def getValueFromRelativePosition(self, value):
601604
"""Return the value in the colorMap from a relative position in the
@@ -814,8 +817,9 @@ def _getRelativePosition(self, val):
814817

815818
if normMin == normMax:
816819
return 0.0
817-
else:
818-
return 1.0 - (normVal - normMin) / (normMax - normMin)
820+
if not numpy.isfinite(normVal):
821+
return 0.0
822+
return 1.0 - (normVal - normMin) / (normMax - normMin)
819823

820824
def _paintTick(self, val, painter, majorTick=True):
821825
"""

0 commit comments

Comments
 (0)