Skip to content

Commit bedd6d5

Browse files
committed
Unify set_pickradius argument
1 parent 33e428d commit bedd6d5

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

lib/matplotlib/axis.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datetime
66
import functools
77
import logging
8+
from numbers import Number
89

910
import numpy as np
1011

@@ -680,7 +681,7 @@ def __init__(self, axes, pickradius=15):
680681

681682
self.labelpad = mpl.rcParams['axes.labelpad']
682683

683-
self.pickradius = pickradius
684+
self._pickradius = pickradius
684685

685686
# Initialize here for testing; later add API
686687
self._major_tick_kw = dict()
@@ -1308,7 +1309,7 @@ def get_offset_text(self):
13081309

13091310
def get_pickradius(self):
13101311
"""Return the depth of the axis used by the picker."""
1311-
return self.pickradius
1312+
return self._pickradius
13121313

13131314
def get_majorticklabels(self):
13141315
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
@@ -1782,9 +1783,17 @@ def set_pickradius(self, pickradius):
17821783
17831784
Parameters
17841785
----------
1785-
pickradius : float
1786+
pickradius : float
1787+
The acceptance radius for containment tests.
1788+
See also `.Axis.contains`.
17861789
"""
1787-
self.pickradius = pickradius
1790+
if not isinstance(pickradius, Number) or pickradius < 0:
1791+
raise ValueError("pick radius should be a distance")
1792+
self._pickradius = pickradius
1793+
1794+
pickradius = property(
1795+
get_pickradius, set_pickradius, doc="The acceptance radius for "
1796+
"containment tests. See also `.Axis.contains`.")
17881797

17891798
# Helper for set_ticklabels. Defining it here makes it picklable.
17901799
@staticmethod
@@ -2168,8 +2177,8 @@ def contains(self, mouseevent):
21682177
return False, {}
21692178
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
21702179
inaxis = 0 <= xaxes <= 1 and (
2171-
b - self.pickradius < y < b or
2172-
t < y < t + self.pickradius)
2180+
b - self._pickradius < y < b or
2181+
t < y < t + self._pickradius)
21732182
return inaxis, {}
21742183

21752184
def set_label_position(self, position):
@@ -2420,8 +2429,8 @@ def contains(self, mouseevent):
24202429
return False, {}
24212430
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
24222431
inaxis = 0 <= yaxes <= 1 and (
2423-
l - self.pickradius < x < l or
2424-
r < x < r + self.pickradius)
2432+
l - self._pickradius < x < l or
2433+
r < x < r + self._pickradius)
24252434
return inaxis, {}
24262435

24272436
def set_label_position(self, position):

lib/matplotlib/collections.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,17 @@ def draw(self, renderer):
422422
renderer.close_group(self.__class__.__name__)
423423
self.stale = False
424424

425-
def set_pickradius(self, pr):
425+
@_api.rename_parameter("3.6", "pr", "pickradius")
426+
def set_pickradius(self, pickradius):
426427
"""
427428
Set the pick radius used for containment tests.
428429
429430
Parameters
430431
----------
431-
pr : float
432+
pickradius : float
432433
Pick radius, in points.
433434
"""
434-
self._pickradius = pr
435+
self._pickradius = pickradius
435436

436437
def get_pickradius(self):
437438
return self._pickradius

lib/matplotlib/lines.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ def __init__(self, xdata, ydata,
385385
# update kwargs before updating data to give the caller a
386386
# chance to init axes (and hence unit support)
387387
self._internal_update(kwargs)
388-
self.pickradius = pickradius
388+
self._pickradius = pickradius
389389
self.ind_offset = 0
390390
if (isinstance(self._picker, Number) and
391391
not isinstance(self._picker, bool)):
392-
self.pickradius = self._picker
392+
self._pickradius = self._picker
393393

394394
self._xorig = np.asarray([])
395395
self._yorig = np.asarray([])
@@ -450,9 +450,9 @@ def contains(self, mouseevent):
450450
# Convert pick radius from points to pixels
451451
if self.figure is None:
452452
_log.warning('no figure set when check if mouse is on line')
453-
pixels = self.pickradius
453+
pixels = self._pickradius
454454
else:
455-
pixels = self.figure.dpi / 72. * self.pickradius
455+
pixels = self.figure.dpi / 72. * self._pickradius
456456

457457
# The math involved in checking for containment (here and inside of
458458
# segment_hits) assumes that it is OK to overflow, so temporarily set
@@ -483,20 +483,21 @@ def get_pickradius(self):
483483
"""
484484
return self._pickradius
485485

486-
def set_pickradius(self, d):
486+
@_api.rename_parameter("3.6", "d", "pickradius")
487+
def set_pickradius(self, pickradius):
487488
"""
488489
Set the pick radius used for containment tests.
489490
490491
See `.contains` for more details.
491492
492493
Parameters
493494
----------
494-
d : float
495+
pickradius : float
495496
Pick radius, in points.
496497
"""
497-
if not isinstance(d, Number) or d < 0:
498+
if not isinstance(pickradius, Number) or pickradius < 0:
498499
raise ValueError("pick radius should be a distance")
499-
self._pickradius = d
500+
self._pickradius = pickradius
500501

501502
pickradius = property(get_pickradius, set_pickradius)
502503

@@ -607,7 +608,7 @@ def set_picker(self, p):
607608
if callable(p):
608609
self._contains = p
609610
else:
610-
self.pickradius = p
611+
self.set_pickradius(p)
611612
self._picker = p
612613

613614
def get_bbox(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy