8000 Turn mouseover into a mpl-style getset_property. · matplotlib/matplotlib@b2f2ec4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2f2ec4

Browse files
committed
Turn mouseover into a mpl-style getset_property.
This allows one to write e.g. `imshow(array, mouseover=False)` instead of `im = imshow(array); im.mouseover = False`. The Python property is kept for backcompat.
1 parent f96eb63 commit b2f2ec4

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

doc/api/artist_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Interactive
3535
Artist.pchanged
3636
Artist.get_cursor_data
3737
Artist.format_cursor_data
38+
Artist.set_mouseover
39+
Artist.get_mouseover
3840
Artist.mouseover
3941
Artist.contains
4042
Artist.pick

lib/matplotlib/artist.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,20 +1295,29 @@ def format_cursor_data(self, data):
12951295
if isinstance(item, Number))
12961296
return "[" + data_str + "]"
12971297

1298-
@property
1299-
def mouseover(self):
1298+
def get_mouseover(self):
13001299
"""
1301-
If this property is set to *True*, the artist will be queried for
1302-
custom context information when the mouse cursor moves over it.
1303-
1304-
See also :meth:`get_cursor_data`, :class:`.ToolCursorPosition` and
1305-
:class:`.NavigationToolbar2`.
1300+
Return whether this artist is queried for custom context information
1301+
when the mouse cursor moves over it.
13061302
"""
13071303
return self._mouseover
13081304

1309-
@mouseover.setter
1310-
def mouseover(self, val):
1311-
val = bool(val)
1305+
def set_mouseover(self, mouseover):
1306+
"""
1307+
Set whether this artist is queried for custom context information when
1308+
the mouse cursor moves over it.
1309+
1310+
Parameters
1311+
----------
1312+
mouseover : bool
1313+
1314+
See Also
1315+
--------
1316+
get_cursor_data
1317+
.ToolCursorPosition
1318+
.NavigationToolbar2
1319+
"""
1320+
val = bool(mouseover)
13121321
self._mouseover = val
13131322
ax = self.axes
13141323
if ax:
@@ -1317,6 +1326,8 @@ def mouseover(self, val):
13171326
else:
13181327
ax._mouseover_set.discard(self)
13191328

1329+
mouseover = property(get_mouseover, set_mouseover) # backcompat.
1330+
13201331

13211332
def _get_tightbbox_for_layout_only(obj, *args, **kwargs):
13221333
"""

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def _set_artist_props(self, a):
11031103
a.set_transform(self.transData)
11041104

11051105
a.axes = self
1106-
if a.mouseover:
1106+
if a.get_mouseover():
11071107
self._mouseover_set.add(a)
11081108

11091109
def _gen_axes_patch(self):

0 commit comments

Comments
 (0)
0