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 c511595

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

File tree

Expand file treeCollapse file tree

7 files changed

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

7 files changed

+45
-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
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Modified APIs
2+
`````````````
3+
The following APIs have been modified:
4+
- ``Axes.mouseover_set`` is now a frozenset, and deprecated. Directly
5+
manipulate the artist's ``.mouseover`` attribute to change their mouseover
6+
status.
7+
18
Removal of deprecated APIs
29
--------------------------
310

‎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
@@ -11,8 +11,8 @@
1111
import matplotlib
1212

1313
from matplotlib import cbook
14-
from matplotlib.cbook import (_check_1d, _string_to_bool, iterable,
15-
index_of, get_label)
14+
from matplotlib.cbook import (
15+
_OrderedSet, _check_1d, _string_to_bool, iterable, index_of, get_label)
1616
from matplotlib import docstring
1717
import matplotlib.colors as mcolors
1818
import matplotlib.lines as mlines
@@ -932,7 +932,7 @@ def _set_artist_props(self, a):
932932

933933
a.axes = self
934934
if a.mouseover:
935-
self.mouseover_set.add(a)
935+
self._mouseover_set.add(a)
936936

937937
def _gen_axes_patch(self):
938938
"""
@@ -1047,7 +1047,7 @@ def cla(self):
10471047
self.tables = []
10481048
self.artists = []
10491049
self.images = []
1050-
self.mouseover_set = set()
1050+
self._mouseover_set = _OrderedSet()
10511051
self._current_image = None # strictly for pyplot via _sci, _gci
10521052
self.legend_ = None
10531053
self.collections = [] # collection.Collection instances
@@ -1114,6 +1114,11 @@ def cla(self):
11141114

11151115
self.stale = True
11161116

1117+
@property
1118+
@cbook.deprecated("3.0")
1119+
def mouseover_set(self):
1120+
return frozenset(self._mouseover_set)
1121+
11171122
def clear(self):
11181123
"""Clear the axes."""
11191124
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.