Skip to content

Commit 02e93e2

Browse files
authored
Merge pull request #23196 from oscargus/pickradiusunification
Unify set_pickradius argument
2 parents 535c953 + 91f47d6 commit 02e93e2

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

doc/api/axis_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Interactive
150150
:nosignatures:
151151

152152
Axis.contains
153+
Axis.pickradius
153154
Axis.get_pickradius
154155
Axis.set_pickradius
155156

lib/matplotlib/axis.py

Lines changed: 16 additions & 7 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

@@ -1357,7 +1358,7 @@ def get_offset_text(self):
13571358

13581359
def get_pickradius(self):
13591360
"""Return the depth of the axis used by the picker."""
1360-
return self.pickradius
1361+
return self._pickradius
13611362

13621363
def get_majorticklabels(self):
13631364
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
@@ -1831,9 +1832,17 @@ def set_pickradius(self, pickradius):
18311832
18321833
Parameters
18331834
----------
1834-
pickradius : float
1835+
pickradius : float
1836+
The acceptance radius for containment tests.
1837+
See also `.Axis.contains`.
18351838
"""
1836-
self.pickradius = pickradius
1839+
if not isinstance(pickradius, Number) or pickradius < 0:
1840+
raise ValueError("pick radius should be a distance")
1841+
self._pickradius = pickradius
1842+
1843+
pickradius = property(
1844+
get_pickradius, set_pickradius, doc="The acceptance radius for "
1845+
"containment tests. See also `.Axis.contains`.")
18371846

18381847
# Helper for set_ticklabels. Defining it here makes it picklable.
18391848
@staticmethod
@@ -2217,8 +2226,8 @@ def contains(self, mouseevent):
22172226
return False, {}
22182227
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
22192228
inaxis = 0 <= xaxes <= 1 and (
2220-
b - self.pickradius < y < b or
2221-
t < y < t + self.pickradius)
2229+
b - self._pickradius < y < b or
2230+
t < y < t + self._pickradius)
22222231
return inaxis, {}
22232232

22242233
def set_label_position(self, position):
@@ -2470,8 +2479,8 @@ def contains(self, mouseevent):
24702479
return False, {}
24712480
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
24722481
inaxis = 0 <= yaxes <= 1 and (
2473-
l - self.pickradius < x < l or
2474-
r < x < r + self.pickradius)
2482+
l - self._pickradius < x < l or
2483+
r < x < r + self._pickradius)
24752484
return inaxis, {}
24762485

24772486
def set_label_position(self, position):

lib/matplotlib/collections.py

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

422-
def set_pickradius(self, pr):
422+
@_api.rename_parameter("3.6", "pr", "pickradius")
423+
def set_pickradius(self, pickradius):
423424
"""
424425
Set the pick radius used for containment tests.
425426
426427
Parameters
427428
----------
428-
pr : float
429+
pickradius : float
429430
Pick radius, in points.
430431
"""
431-
self._pickradius = pr
432+
self._pickradius = pickradius
432433

433434
def get_pickradius(self):
434435
return self._pickradius

lib/matplotlib/lines.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,11 @@ def __init__(self, xdata, ydata,
390390
# update kwargs before updating data to give the caller a
391391
# chance to init axes (and hence unit support)
392392
self._internal_update(kwargs)
393-
self.pickradius = pickradius
393+
self._pickradius = pickradius
394394
self.ind_offset = 0
395395
if (isinstance(self._picker, Number) and
396396
not isinstance(self._picker, bool)):
397-
self.pickradius = self._picker
397+
self._pickradius = self._picker
398398

399399
self._xorig = np.asarray([])
400400
self._yorig = np.asarray([])
@@ -455,9 +455,9 @@ def contains(self, mouseevent):
455455
# Convert pick radius from points to pixels
456456
if self.figure is None:
457457
_log.warning('no figure set when check if mouse is on line')
458-
pixels = self.pickradius
458+
pixels = self._pickradius
459459
else:
460-
pixels = self.figure.dpi / 72. * self.pickradius
460+
pixels = self.figure.dpi / 72. * self._pickradius
461461

462462
# The math involved in checking for containment (here and inside of
463463
# segment_hits) assumes that it is OK to overflow, so temporarily set
@@ -488,20 +488,21 @@ def get_pickradius(self):
488488
"""
489489
return self._pickradius
490490

491-
def set_pickradius(self, d):
491+
@_api.rename_parameter("3.6", "d", "pickradius")
492+
def set_pickradius(self, pickradius):
492493
"""
493494
Set the pick radius used for containment tests.
494495
495496
See `.contains` for more details.
496497
497498
Parameters
498499
----------
499-
d : float
500+
pickradius : float
500501
Pick radius, in points.
501502
"""
502-
if not isinstance(d, Number) or d < 0:
503+
if not isinstance(pickradius, Number) or pickradius < 0:
503504
raise ValueError("pick radius should be a distance")
504-
self._pickradius = d
505+
self._pickradius = pickradius
505506

506507
pickradius = property(get_pickradius, set_pickradius)
507508

@@ -612,7 +613,7 @@ def set_picker(self, p):
612613
if callable(p):
613614
self._contains = p
614615
else:
615-
self.pickradius = p
616+
self.set_pickradius(p)
616617
self._picker = p
617618

618619
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