From 6fc875a7323e85d1434724f427631cef88a0714f Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 20 Aug 2020 14:33:30 +0800 Subject: [PATCH 1/4] Fix canvas redraws during motion in figures with a Button or TextBox During motion in figures with Button or TextBox widgets, the stored `color` and `hovercolor` values are compared with the current Axes facecolor. By default, the stored colors are each a string of a float, but the returned facecolor is frequently a tuple of RGBA values. The colors appear to mismatch, triggering a draw event with any motion in the figure. As a fix, convert both the color and facecolor values to RGBA format for comparison in case either value is stored in a different format. --- lib/matplotlib/widgets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 0ae44392f303..5f37b2ea7409 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -16,7 +16,7 @@ import numpy as np import matplotlib as mpl -from . import cbook, ticker +from . import cbook, ticker, colors from .lines import Line2D from .patches import Circle, Rectangle, Ellipse from .transforms import blended_transform_factory @@ -220,7 +220,7 @@ def _motion(self, event): if self.ignore(event): return c = self.hovercolor if event.inaxes == self.ax else self.color - if c != self.ax.get_facecolor(): + if colors.to_rgba(c) != colors.to_rgba(self.ax.get_facecolor()): self.ax.set_facecolor(c) if self.drawon: self.ax.figure.canvas.draw() @@ -920,7 +920,7 @@ def _motion(self, event): if self.ignore(event): return c = self.hovercolor if event.inaxes == self.ax else self.color - if c != self.ax.get_facecolor(): + if colors.to_rgba(c) != colors.to_rgba(self.ax.get_facecolor()): self.ax.set_facecolor(c) if self.drawon: self.ax.figure.canvas.draw() From 2bdf3b0a7de60e560e040464a31fb48b508f65f8 Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 21 Aug 2020 11:47:36 +0800 Subject: [PATCH 2/4] Update lib/matplotlib/widgets.py Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 5f37b2ea7409..39ae3f5e0b00 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -16,7 +16,7 @@ import numpy as np import matplotlib as mpl -from . import cbook, ticker, colors +from . import cbook, colors, ticker from .lines import Line2D from .patches import Circle, Rectangle, Ellipse from .transforms import blended_transform_factory From 8d37446c97cf858c47b6b82e7ac9e2553f8addbc Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 21 Aug 2020 11:48:47 +0800 Subject: [PATCH 3/4] Update lib/matplotlib/widgets.py Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 39ae3f5e0b00..deea4aa71c32 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -220,7 +220,7 @@ def _motion(self, event): if self.ignore(event): return c = self.hovercolor if event.inaxes == self.ax else self.color - if colors.to_rgba(c) != colors.to_rgba(self.ax.get_facecolor()): + if not colors.same_color(c, self.ax.get_facecolor()): self.ax.set_facecolor(c) if self.drawon: self.ax.figure.canvas.draw() From 0c6b9646a382d7bd2773d4bf362f65c97efa6272 Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 21 Aug 2020 11:55:18 +0800 Subject: [PATCH 4/4] Update lib/matplotlib/widgets.py --- lib/matplotlib/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index deea4aa71c32..7537bebd251b 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -920,7 +920,7 @@ def _motion(self, event): if self.ignore(event): return c = self.hovercolor if event.inaxes == self.ax else self.color - if colors.to_rgba(c) != colors.to_rgba(self.ax.get_facecolor()): + if not colors.same_color(c, self.ax.get_facecolor()): self.ax.set_facecolor(c) if self.drawon: self.ax.figure.canvas.draw()