Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0804eeb

Browse files
committed
Minor fixes and testing
1 parent 8423793 commit 0804eeb

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

lib/matplotlib/artist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def set_hover(self, hover):
640640
641641
Parameters
642642
----------
643-
hover : None or bool
643+
hover : None or bool or float or function
644644
This can be one of the following:
645645
646646
- *None*: Hover is disabled for this artist (default).
@@ -663,6 +663,8 @@ def set_hover(self, hover):
663663
is over the artist, return *hit=True* and props is a dictionary of
664664
properties you want added to the HoverEvent attributes.
665665
"""
666+
if not self.figure and hover is not None:
667+
raise ValueError("Cannot hover without an existing figure")
666668
self._hover = hover
667669

668670
def get_hover(self):

lib/matplotlib/backends/_backend_tk.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,6 @@ def leave_notify_event(self, event):
311311
modifiers=self._mpl_modifiers(event),
312312
guiEvent=event)._process()
313313

314-
def hover_event(self, event):
315-
artist = event.artist
316-
if not artist.get_hover:
317-
thismouse = MouseEvent("motion_hover_event", self,
318-
*self.mouseEventCoords(event),
319-
modifiers=self._mpl_modifiers(),
320-
guiEvent=event)
321-
HoverEvent("motion_hover_event", self,
322-
thismouse, artist, None)._process()
323-
# make tooltip corresponding to this? this part doesn't exactly work
324-
325314
def button_press_event(self, event, dblclick=False):
326315
# set focus to the canvas so that it can receive keyboard events
327316
self._tkcanvas.focus_set()

lib/matplotlib/tests/test_artist.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,24 @@ def test_set_alpha_for_array():
325325
art._set_alpha_for_array([0.5, np.nan])
326326

327327

328+
def test_set_hover():
329+
art = martist.Artist() # blank canvas
330+
with pytest.raises(ValueError, match="Cannot hover without an existing figure"):
331+
art.set_hover(True)
332+
333+
fig, ax = plt.subplots()
334+
im = ax.imshow(np.arange(36).reshape(6, 6)) # non-blank canvasses
335+
ln, = ax.plot(range(5))
336+
im.set_hover(True)
337+
assert im.get_hover() == True
338+
im.set_hover(1.0)
339+
assert ln.get_hover() == 1.0
340+
ln.set_hover(art.__str__)
341+
assert ln.get_hover() is not None
342+
343+
im.remove()
344+
ln.remove()
345+
328346
def test_callbacks():
329347
def func(artist):
330348
func.counter += 1

0 commit comments

Comments
 (0)