Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aaff400

Browse filesBrowse files
committed
Maintain artist addition order in Axes.mouseover_set.
1 parent a53a04c commit aaff400
Copy full SHA for aaff400

File tree

Expand file treeCollapse file tree

7 files changed

+47
-12
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+47
-12
lines changed

‎doc/api/next_api_changes/2018-02-26-AL-removals.rst

Copy file name to clipboardExpand all lines: doc/api/next_api_changes/2018-02-26-AL-removals.rst
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Modified APIs
2+
-------------
3+
4+
The following APIs have been modified:
5+
6+
- ``Axes.mouseover_set`` is now a frozenset, and deprecated. Directly
7+
manipulate the artist's ``.mouseover`` attribute to change their mouseover
8+
status.
9+
110
Removal of deprecated APIs
211
--------------------------
312

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def remove(self):
148148
_ax_flag = False
149149
if hasattr(self, 'axes') and self.axes:
150150
# remove from the mouse hit list
151-
self.axes.mouseover_set.discard(self)
151+
self.axes._mouseover_set.discard(self)
152152
# mark the axes as stale
153153
self.axes.stale = True
154154
# decouple the artist from the axes
@@ -1028,9 +1028,9 @@ def mouseover(self, val):
10281028
ax = self.axes
10291029
if ax:
10301030
if val:
1031-
ax.mouseover_set.add(self)
1031+
ax._mouseover_set.add(self)
10321032
else:
1033-
ax.mouseover_set.discard(self)
1033+
ax._mouseover_set.discard(self)
10341034

10351035

10361036
class ArtistInspector(object):

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import matplotlib
1313

1414
from matplotlib import cbook, rcParams
15-
from matplotlib.cbook import (_check_1d, _string_to_bool, iterable,
16-
index_of, get_label)
15+
from matplotlib.cbook import (
16+
_OrderedSet, _check_1d, _string_to_bool, iterable, index_of, get_label)
1717
from matplotlib import docstring
1818
import matplotlib.colors as mcolors
1919
import matplotlib.lines as mlines
@@ -907,7 +907,7 @@ def _set_artist_props(self, a):
907907

908908
a.axes = self
909909
if a.mouseover:
910-
self.mouseover_set.add(a)
910+
self._mouseover_set.add(a)
911911

912912
def _gen_axes_patch(self):
913913
"""
@@ -1022,7 +1022,7 @@ def cla(self):
10221022
self.tables = []
10231023
self.artists = []
10241024
self.images = []
1025-
self.mouseover_set = set()
1025+
self._mouseover_set = _OrderedSet()
10261026
self._current_image = None # strictly for pyplot via _sci, _gci
10271027
self.legend_ = None
10281028
self.collections = [] # collection.Collection instances
@@ -1089,6 +1089,11 @@ def cla(self):
10891089

10901090
self.stale = True
10911091

1092+
@property
1093+
@cbook.deprecated("3.0")
1094+
def mouseover_set(self):
1095+
return frozenset(self._mouseover_set)
1096+
10921097
def clear(self):
10931098
"""Clear the axes."""
10941099
self.cla()

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ def mouse_move(self, event):
27052705
except (ValueError, OverflowError):
27062706
pass
27072707
else:
2708-
artists = [a for a in event.inaxes.mouseover_set
2708+
artists = [a for a in event.inaxes._mouseover_set
27092709
if a.contains(event) and a.get_visible()]
27102710

27112711
if artists:

‎lib/matplotlib/backend_tools.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_tools.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def send_message(self, event):
337337
except (ValueError, OverflowError):
338338
pass
339339
else:
340-
artists = [a for a in event.inaxes.mouseover_set
340+
artists = [a for a in event.inaxes._mouseover_set
341341
if a.contains(event) and a.get_visible()]
342342

343343
if artists:

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,3 +2047,24 @@ def _warn_external(message, category=None):
20472047
break
20482048
frame = frame.f_back
20492049
warnings.warn(message, category, stacklevel)
2050+
2051+
2052+
class _OrderedSet(collections.MutableSet):
2053+
def __init__(self):
2054+
self._od = collections.OrderedDict()
2055+
2056+
def __contains__(self, key):
2057+
return key in self._od
2058+
2059+
def __iter__(self):
2060+
return iter(self._od)
2061+
2062+
def __len__(self):
2063+
return len(self._od)
2064+
2065+
def add(self, key):
2066+
self._od.pop(key, None)
2067+
self._od[key] = None
2068+
2069+
def discard(self, key):
2070+
self._od.pop(key, None)

‎lib/matplotlib/tests/test_artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_artist.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def test_remove():
185185
assert not ax.stale
186186
assert not ln.stale
187187

188-
assert im in ax.mouseover_set
189-
assert ln not in ax.mouseover_set
188+
assert im in ax._mouseover_set
189+
assert ln not in ax._mouseover_set
190190
assert im.axes is ax
191191

192192
im.remove()
@@ -196,7 +196,7 @@ def test_remove():
196196
assert art.axes is None
197197
assert art.figure is None
198198

199-
assert im not in ax.mouseover_set
199+
assert im not in ax._mouseover_set
200200
assert fig.stale
201201
assert ax.stale
202202

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.