diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 2fe2ad59ac42..e11144ff8f8a 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2010,8 +2010,14 @@ def enter_notify_event(self, guiEvent=None, xy=None): if xy is not None: x, y = xy self._lastx, self._lasty = x, y + else: + x = None + y = None + cbook.warn_deprecated('3.0', 'enter_notify_event expects a ' + 'location but ' + 'your backend did not pass one.') - event = Event('figure_enter_event', self, guiEvent) + event = LocationEvent('figure_enter_event', self, x, y, guiEvent) self.callbacks.process('figure_enter_event', event) @cbook.deprecated("2.1") diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index e5ef40caf74f..6230511f7361 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -178,6 +178,8 @@ def __init__(self, figure, master=None, resize_callback=None): self._tkcanvas.bind("", self.resize) self._tkcanvas.bind("", self.key_press) self._tkcanvas.bind("", self.motion_notify_event) + self._tkcanvas.bind("", self.enter_notify_event) + self._tkcanvas.bind("", self.leave_notify_event) self._tkcanvas.bind("", self.key_release) for name in "", "", "": self._tkcanvas.bind(name, self.button_press_event) @@ -326,6 +328,11 @@ def motion_notify_event(self, event): y = self.figure.bbox.height - event.y FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event) + def enter_notify_event(self, event): + x = event.x + # flipy so y=0 is bottom of canvas + y = self.figure.bbox.height - event.y + FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y)) def button_press_event(self, event, dblclick=False): x = event.x diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 573110aaac1c..0bbab45c0a8b 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -225,7 +225,10 @@ def leave_notify_event(self, widget, event): FigureCanvasBase.leave_notify_event(self, event) def enter_notify_event(self, widget, event): - FigureCanvasBase.enter_notify_event(self, event) + x = event.x + # flipy so y=0 is bottom of canvas + y = self.get_allocation().height - event.y + FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y)) def size_allocate(self, widget, allocation): dpival = self.figure.dpi diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index b1a75b248dd8..a3757d6000bf 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -299,7 +299,8 @@ def get_width_height(self): return int(w / self._dpi_ratio), int(h / self._dpi_ratio) def enterEvent(self, event): - FigureCanvasBase.enter_notify_event(self, guiEvent=event) + x, y = self.mouseEventCoords(event.pos()) + FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y)) def leaveEvent(self, event): QtWidgets.QApplication.restoreOverrideCursor() diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 81b0729b65d8..ada580d0077c 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -1053,7 +1053,10 @@ def _onLeave(self, evt): def _onEnter(self, evt): """Mouse has entered the window.""" - FigureCanvasBase.enter_notify_event(self, guiEvent=evt) + x = evt.GetX() + y = self.figure.bbox.height - evt.GetY() + evt.Skip() + FigureCanvasBase.enter_notify_event(self, guiEvent=evt, xy=(x, y)) class FigureCanvasWx(_FigureCanvasWxBase):