Repository: silx-kit/silx
Issue: ValueError: Axis limits cannot be NaN or Inf

Here is an issue from Flint with some curve using a monitor containing a 0.
```
Traceback (most recent call last):
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/utils/refresh_helper.py", line 55, in __update
    self.__aggregator.flush()
  File "/users/valls/workspace/bliss.git/bliss/flint/utils/signalutils.py", line 105, in flush
    callback(*args, **kwargs)
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/curve_plot.py", line 388, in __structureChanged
    self.__redrawAllScans()
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/curve_plot.py", line 643, in __redrawAllScans
    self.__redrawScan(currentScan)
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/curve_plot.py", line 684, in __redrawScan
    self.__updatePlotItem(item, scan)
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/curve_plot.py", line 870, in __updatePlotItem
    self.__updatePlotZoom(updateZoomNow)
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/curve_plot.py", line 874, in __updatePlotZoom
    self.__view.plotUpdated()
  File "/users/valls/workspace/bliss.git/bliss/flint/widgets/utils/view_helper.py", line 55, in plotUpdated
    self.__plot.resetZoom()
  File "/users/valls/Software/miniconda3/envs/blissenv/lib/python3.7/site-packages/silx/gui/plot/PlotWidget.py", line 2890, in resetZoom
    self._forceResetZoom(dataMargins=dataMargins)
  File "/users/valls/Software/miniconda3/envs/blissenv/lib/python3.7/site-packages/silx/gui/plot/PlotWidget.py", line 2854, in _forceResetZoom
    self.setLimits(*newLimits)
  File "/users/valls/Software/miniconda3/envs/blissenv/lib/python3.7/site-packages/silx/gui/plot/PlotWidget.py", line 2321, in setLimits
    self._backend.setLimits(xmin, xmax, ymin, ymax, y2min, y2max)
  File "/users/valls/Software/miniconda3/envs/blissenv/lib/python3.7/site-packages/silx/gui/plot/backends/BackendMatplotlib.py", line 1052, in setLimits
    self.ax2.set_ylim(min(y2min, y2max), max(y2min, y2max))
  File "/users/valls/Software/miniconda3/envs/blissenv/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 3622, in set_ylim
    bottom = self._validate_converted_limits(bottom, self.convert_yunits)
  File "/users/valls/Software/miniconda3/envs/blissenv/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 3158, in _validate_converted_limits
    raise ValueError("Axis limits cannot be NaN or Inf")
ValueError: Axis limits cannot be NaN or Inf
```

Here is the content of `xmin, xmax, ymin, ymax, y2min, y2max`
```
(-0.02, 1.02, -inf, inf, -inf, inf)
```
It would be nice to filter inf?

Changed files:
silx/gui/plot/test/testPlotWidget.py, silx/gui/plot/items/core.py

diff --git a/silx/gui/plot/items/core.py b/silx/gui/plot/items/core.py
index 9426a130b..586ba3e2c 100644
--- a/silx/gui/plot/items/core.py
+++ b/silx/gui/plot/items/core.py
@@ -45,6 +45,7 @@ import six
 
 from ....utils.deprecation import deprecated
 from ....utils.enum import Enum as _Enum
+from ....math.combo import min_max
 from ... import qt
 from ... import colors
 from ...colors import Colormap
@@ -1347,15 +1348,11 @@ class PointsBase(Item, SymbolMixIn, AlphaMixIn):
             else:
                 x, y, _xerror, _yerror = data
 
-            with warnings.catch_warnings():
-                warnings.simplefilter('ignore', category=RuntimeWarning)
-                # Ignore All-NaN slice encountered
-                self._boundsCache[(xPositive, yPositive)] = (
-                    numpy.nanmin(x),
-                    numpy.nanmax(x),
-                    numpy.nanmin(y),
-                    numpy.nanmax(y)
-                )
+            xmin, xmax = min_max(x, finite=True)
+            ymin, ymax = min_max(y, finite=True)
+            self._boundsCache[(xPositive, yPositive)] = tuple([
+                (bound if bound is not None else numpy.nan)
+                for bound in (xmin, xmax, ymin, ymax)])
         return self._boundsCache[(xPositive, yPositive)]
 
     def _getCachedData(self):
diff --git a/silx/gui/plot/test/testPlotWidget.py b/silx/gui/plot/test/testPlotWidget.py
index 94143e8a1..b439c34ee 100755
--- a/silx/gui/plot/test/testPlotWidget.py
+++ b/silx/gui/plot/test/testPlotWidget.py
@@ -455,6 +455,21 @@ class TestPlotCurve(PlotWidgetTestCase):
 
         self.plot.setActiveCurveHandling(False)
 
+    def testPlotCurveInfinite(self):
+        """Test plot curves with not finite data"""
+        tests = {
+            'y all not finite': ([0, 1, 2], [numpy.inf, numpy.nan, -numpy.inf]),
+            'x all not finite': ([numpy.inf, numpy.nan, -numpy.inf], [0, 1, 2]),
+            'x some inf': ([0, numpy.inf, 2], [0, 1, 2]),
+            'y some inf': ([0, 1, 2], [0, numpy.inf, 2])
+        }
+        for name, args in tests.items():
+            with self.subTest(name):
+                self.plot.addCurve(*args)
+                self.plot.resetZoom()
+                self.qapp.processEvents()
+                self.plot.clear()
+
     def testPlotCurveColorFloat(self):
         color = numpy.array(numpy.random.random(3 * 1000),
                             dtype=numpy.float32).reshape(1000, 3)