Repository: silx-kit/silx
Issue: [roi example] We have to click on the plot to display the first ROIs

Feedback from @tiagocoutinho.

I also can notice it here now. When my manager choose to not display the example windows close to another existing windows. Then maybe there is a missing repaint somewhere.

Changed files:
silx/gui/plot/backends/BackendMatplotlib.py

diff --git a/silx/gui/plot/backends/BackendMatplotlib.py b/silx/gui/plot/backends/BackendMatplotlib.py
index 0d10a4c1d..49c454019 100644
--- a/silx/gui/plot/backends/BackendMatplotlib.py
+++ b/silx/gui/plot/backends/BackendMatplotlib.py
@@ -35,6 +35,8 @@ import logging
 import datetime as dt
 import numpy
 
+from pkg_resources import parse_version as _parse_version
+
 
 _logger = logging.getLogger(__name__)
 
@@ -222,6 +224,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
         # when getting the limits at the expense of a replot
         self._dirtyLimits = True
         self._axesDisplayed = True
+        self._matplotlibVersion = _parse_version(matplotlib.__version__)
 
         self.fig = Figure()
         self.fig.set_facecolor("w")
@@ -245,7 +248,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
         self.ax2.set_autoscaley_on(True)
         self.ax.set_zorder(1)
         # this works but the figure color is left
-        if matplotlib.__version__[0] < '2':
+        if self._matplotlibVersion < _parse_version('2'):
             self.ax.set_axis_bgcolor('none')
         else:
             self.ax.set_facecolor('none')
@@ -257,7 +260,6 @@ class BackendMatplotlib(BackendBase.BackendBase):
         self._colormaps = {}
 
         self._graphCursor = tuple()
-        self.matplotlibVersion = matplotlib.__version__
 
         self._enableAxis('right', False)
         self._isXAxisTimeSeries = False
@@ -379,7 +381,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
         # No transparent colormap with matplotlib < 1.2.0
         # Add support for transparent colormap for uint8 data with
         # colormap with 256 colors, linear norm, [0, 255] range
-        if matplotlib.__version__ < '1.2.0':
+        if self._matplotlibVersion < _parse_version('1.2.0'):
             if (len(data.shape) == 2 and colormap.getName() is None and
                     colormap.getColormapLUT() is not None):
                 colors = colormap.getColormapLUT()
@@ -437,7 +439,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
             ystep = 1 if scale[1] >= 0. else -1
             data = data[::ystep, ::xstep]
 
-        if matplotlib.__version__ < "2.1":
+        if self._matplotlibVersion < _parse_version('2.1'):
             # matplotlib 1.4.2 do not support float128
             dtype = data.dtype
             if dtype.kind == "f" and dtype.itemsize >= 16:
@@ -784,7 +786,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
         # Workaround for matplotlib 2.1.0 when one tries to set an axis
         # to log scale with both limits <= 0
         # In this case a draw with positive limits is needed first
-        if flag and matplotlib.__version__ >= '2.1.0':
+        if flag and self._matplotlibVersion >= _parse_version('2.1.0'):
             xlim = self.ax.get_xlim()
             if xlim[0] <= 0 and xlim[1] <= 0:
                 self.ax.set_xlim(1, 10)
@@ -796,7 +798,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
     def setYAxisLogarithmic(self, flag):
         # Workaround for matplotlib 2.0 issue with negative bounds
         # before switching to log scale
-        if flag and matplotlib.__version__ >= '2.0.0':
+        if flag and self._matplotlibVersion >= _parse_version('2.0.0'):
             redraw = False
             for axis, dataRangeIndex in ((self.ax, 1), (self.ax2, 2)):
                 ylim = axis.get_ylim()
@@ -1055,7 +1057,7 @@ class BackendMatplotlibQt(FigureCanvasQTAgg, BackendMatplotlib):
         """
         # Starting with mpl 2.1.0, toggling autoscale raises a ValueError
         # in some situations. See #1081, #1136, #1163,
-        if matplotlib.__version__ >= "2.0.0":
+        if self._matplotlibVersion >= _parse_version("2.0.0"):
             try:
                 FigureCanvasQTAgg.draw(self)
             except ValueError as err:
@@ -1087,7 +1089,6 @@ class BackendMatplotlibQt(FigureCanvasQTAgg, BackendMatplotlib):
             if yRightLimits != self.ax2.get_ybound():
                 self._plot.getYAxis(axis='right')._emitLimitsChanged()
 
-
         self._drawOverlays()
 
     def replot(self):
@@ -1106,6 +1107,12 @@ class BackendMatplotlibQt(FigureCanvasQTAgg, BackendMatplotlib):
         elif dirtyFlag:  # Need full redraw
             self.draw()
 
+        # Workaround issue of rendering overlays with some matplotlib versions
+        if (_parse_version('1.5') <= self._matplotlibVersion < _parse_version('2.1') and
+                not hasattr(self, '_firstReplot')):
+            self._firstReplot = False
+            if self._overlays or self._graphCursor:
+                qt.QTimer.singleShot(0, self.draw)  # Request async draw
 
     # cursor