diff --git a/doc/api/next_api_changes/deprecations/19336-AL.rst b/doc/api/next_api_changes/deprecations/19336-AL.rst new file mode 100644 index 000000000000..b77bca4c8cf5 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/19336-AL.rst @@ -0,0 +1,3 @@ +Setting a Line2D's pickradius via ``set_picker`` is undeprecated +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This cancels the deprecation introduced in Matplotlib 3.3.0. diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index a3dfebcaf233..ced1e002d385 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -539,7 +539,7 @@ def set_picker(self, picker): Parameters ---------- - picker : None or bool or callable + picker : None or bool or float or callable This can be one of the following: - *None*: Picking is disabled for this artist (default). @@ -548,6 +548,14 @@ def set_picker(self, picker): artist will fire a pick event if the mouse event is over the artist. + - A float: If picker is a number it is interpreted as an + epsilon tolerance in points and the artist will fire + off an event if its data is within epsilon of the mouse + event. For some artists like lines and patch collections, + the artist may provide additional data to the pick event + that is generated, e.g., the indices of the data within + epsilon of the pick event + - A function: If picker is callable, it is a user supplied function which determines whether the artist is hit by the mouse event:: @@ -557,11 +565,6 @@ def set_picker(self, picker): to determine the hit test. if the mouse event is over the artist, return *hit=True* and props is a dictionary of properties you want added to the PickEvent attributes. - - - *deprecated*: For `.Line2D` only, *picker* can also be a float - that sets the tolerance for checking whether an event occurred - "on" the line; this is deprecated. Use `.Line2D.set_pickradius` - instead. """ self._picker = picker diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index e502ff119253..bac48f3522c2 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -397,6 +397,8 @@ def __init__(self, xdata, ydata, self.update(kwargs) self.pickradius = pickradius self.ind_offset = 0 + if isinstance(self._picker, Number): + self.pickradius = self._picker self._xorig = np.asarray([]) self._yorig = np.asarray([]) @@ -601,13 +603,17 @@ def get_markevery(self): return self._markevery def set_picker(self, p): - # docstring inherited - if isinstance(p, Number) and not isinstance(p, bool): - # After deprecation, the whole method can be deleted and inherited. - _api.warn_deprecated( - "3.3", message="Setting the line's pick radius via set_picker " - "is deprecated since %(since)s and will be removed " - "%(removal)s; use set_pickradius instead.") + """ + Sets the event picker details for the line. + + Parameters + ---------- + p : float or callable[[Artist, Event], Tuple[bool, dict]] + If a float, it is used as the pick radius in points. + """ + if callable(p): + self._contains = p + else: self.pickradius = p self._picker = p