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 cba092c

Browse filesBrowse files
committed
Maintain artist addition order in Axes.mouseover_set.
1 parent 31d2c2f commit cba092c
Copy full SHA for cba092c

File tree

Expand file treeCollapse file tree

5 files changed

+41
-10
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

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

‎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
@@ -1047,9 +1047,9 @@ def mouseover(self, val):
10471047
ax = self.axes
10481048
if ax:
10491049
if val:
1050-
ax.mouseover_set.add(self)
1050+
ax._mouseover_set.add(self)
10511051
else:
1052-
ax.mouseover_set.discard(self)
1052+
ax._mouseover_set.discard(self)
10531053

10541054

10551055
class ArtistInspector(object):

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+8-4Lines changed: 8 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
@@ -933,7 +933,7 @@ def _set_artist_props(self, a):
933933

934934
a.axes = self
935935
if a.mouseover:
936-
self.mouseover_set.add(a)
936+
self._mouseover_set.add(a)
937937

938938
def _gen_axes_patch(self):
939939
"""
@@ -1048,7 +1048,7 @@ def cla(self):
10481048
self.tables = []
10491049
self.artists = []
10501050
self.images = []
1051-
self.mouseover_set = set()
1051+
self._mouseover_set = _OrderedSet()
10521052
self._current_image = None # strictly for pyplot via _sci, _gci
10531053
self.legend_ = None
10541054
self.collections = [] # collection.Collection instances
@@ -1115,6 +1115,10 @@ def cla(self):
11151115

11161116
self.stale = True
11171117

1118+
@property
1119+
def mouseover_set(self):
1120+
return frozenset(self._mouseover_set)
1121+
11181122
def clear(self):
11191123
"""Clear the axes."""
11201124
self.cla()

‎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
@@ -2032,3 +2032,24 @@ def _setattr_cm(obj, **kwargs):
20322032
delattr(obj, attr)
20332033
else:
20342034
setattr(obj, attr, orig)
2035+
2036+
2037+
class _OrderedSet(collections.MutableSet):
2038+
def __init__(self):
2039+
self._od = collections.OrderedDict()
2040+
2041+
def __contains__(self, key):
2042+
return key in self._od
2043+
2044+
def __iter__(self):
2045+
return iter(self._od)
2046+
2047+
def __len__(self):
2048+
return len(self._od)
2049+
2050+
def add(self, key):
2051+
self._od.pop(key, None)
2052+
self._od[key] = None
2053+
2054+
def discard(self, key):
2055+
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.