Skip to content

Commit 509e5dd

Browse files
committed
artist.set_picker(False) no longer keeps artists pickable
The documentation for `set_picker` currently states that `None` disables picking, `True` enables picking, and a custom callable implements, well, custom picking behavior. It turns out that `False` *also* enables picking, because the relevant check is implemented in `Artist.pickable`, which strictly checks `picker is not None` (and also checks that the artist has been added to a figure). This can indeed be verified with ```python from pylab import * plot([1, 2], picker=False); gcf().canvas.mpl_connect("pick_event", print) ``` and clicking on the line. Strictly speaking, the docs state nothing about `False`, so the behavior does not violate the docs, but that's clearly non-optimal behavior, which I'm proposing to change here.
1 parent 5960b5a commit 509e5dd

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``artist.set_picker(False)`` disables artist picking
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Previously, setting the ``picker`` property of an artist to any non-None value, including ``False``, would keep picking enabled. This was deemed a bug; now, truthy values enable picking and falsy ones disable it. The default is now ``False`` instead of ``None``, but both mean that picking is disabled by default.

lib/matplotlib/artist.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(self):
111111
self._clippath = None
112112
self._clipon = True
113113
self._label = ''
114-
self._picker = None
114+
self._picker = False
115115
self._contains = None
116116
self._rasterized = False
117117
self._agg_filter = None
@@ -496,7 +496,7 @@ def pickable(self):
496496
--------
497497
set_picker, get_picker, pick
498498
"""
499-
return self.figure is not None and self._picker is not None
499+
return self.figure is not None and self._picker
500500

501501
def pick(self, mouseevent):
502502
"""
@@ -539,14 +539,12 @@ def set_picker(self, picker):
539539
540540
Parameters
541541
----------
542-
picker : None or bool or callable
542+
picker : bool or callable
543543
This can be one of the following:
544544
545-
- *None*: Picking is disabled for this artist (default).
546-
547-
- A boolean: If *True* then picking will be enabled and the
548-
artist will fire a pick event if the mouse event is over
549-
the artist.
545+
- A boolean: Whether picking is enabled, i.e. whether the
546+
artist fires a pick event when the mouse event occurs over
547+
the artist. The default is False, i.e. picking is disabled.
550548
551549
- A function: If picker is callable, it is a user supplied
552550
function which determines whether the artist is hit by the

lib/matplotlib/patches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def get_verts(self):
123123
def _process_radius(self, radius):
124124
if radius is not None:
125125
return radius
126-
if isinstance(self._picker, Number):
126+
if (isinstance(self._picker, Number)
127+
and not isinstance(self._picker, bool)):
127128
_radius = self._picker
128129
else:
129130
if self.get_edgecolor()[3] == 0:

0 commit comments

Comments
 (0)