Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit137a3b5

Browse files
committed
Deprecate setting a Collection's pickradius via set_picker.
This is the same deprecation as the one introduced for Line2D in 3.3.(The exact deprecation strategy used here may already break convolutedcall sequences: calling`coll.set_pickradius(3); coll.set_picker(5); coll.set_picker(False); coll.set_picker(True)`will leave the pickradius at 5 instead of 3 as was the case before, butI'm not too worried about that (if anything the new behavior is moresensical...).)
1 parent7e59e29 commit137a3b5

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Setting Collection's pickradius via ``.Collection.set_picker``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Setting a `.Collection`\'s pickradius (i.e. the tolerance for pick events
4+
and containment checks) via `.Collection.set_picker` is deprecated. Use
5+
`.Collection.set_pickradius` instead.

‎lib/matplotlib/artist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ def set_picker(self, picker):
558558
artist, return *hit=True* and props is a dictionary of
559559
properties you want added to the PickEvent attributes.
560560
561-
- *deprecated*: For `.Line2D`only, *picker* can also be a float
562-
that sets the tolerance for checking whether an event occurred
563-
"on" theline; this is deprecated. Use `.Line2D.set_pickradius`
564-
instead.
561+
- *deprecated*: For `.Line2D`and `.Collection`, *picker* can also
562+
be a floatthat sets the tolerance for checking whether an event
563+
occurred"on" theartist; this is deprecated. Use
564+
`.Line2D.set_pickradius`/`.Collection.set_pickradius`instead.
565565
"""
566566
self._picker=picker
567567

‎lib/matplotlib/collections.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ def draw(self, renderer):
415415
renderer.close_group(self.__class__.__name__)
416416
self.stale=False
417417

418+
defset_picker(self,p):
419+
# docstring inherited
420+
ifisinstance(p,Number)andnotisinstance(p,bool):
421+
# After deprecation, the whole method can be deleted and inherited.
422+
cbook.warn_deprecated(
423+
"3.4",message="Setting the collections's pick radius via "
424+
"set_picker is deprecated since %(since)s and will be removed "
425+
"%(removal)s; use set_pickradius instead.")
426+
self.set_pickradius(p)
427+
self._picker=p
428+
418429
defset_pickradius(self,pr):
419430
"""
420431
Set the pick radius used for containment tests.
@@ -439,32 +450,21 @@ def contains(self, mouseevent):
439450
inside,info=self._default_contains(mouseevent)
440451
ifinsideisnotNone:
441452
returninside,info
442-
443453
ifnotself.get_visible():
444454
returnFalse, {}
445-
446-
pickradius= (
447-
float(self._picker)
448-
ifisinstance(self._picker,Number)and
449-
self._pickerisnotTrue# the bool, not just nonzero or 1
450-
elseself._pickradius)
451-
452455
ifself.axes:
453456
self.axes._unstale_viewLim()
454-
455457
transform,transOffset,offsets,paths=self._prepare_points()
456-
457458
# Tests if the point is contained on one of the polygons formed
458459
# by the control points of each of the paths. A point is considered
459460
# "on" a path if it would lie within a stroke of width 2*pickradius
460461
# following the path. If pickradius <= 0, then we instead simply check
461462
# if the point is *inside* of the path instead.
462463
ind=_path.point_in_path_collection(
463-
mouseevent.x,mouseevent.y,pickradius,
464+
mouseevent.x,mouseevent.y,self._pickradius,
464465
transform.frozen(),paths,self.get_transforms(),
465-
offsets,transOffset,pickradius<=0,
466+
offsets,transOffset,self._pickradius<=0,
466467
self._offset_position)
467-
468468
returnlen(ind)>0,dict(ind=ind)
469469

470470
defset_urls(self,urls):

‎lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ def test_hexbin_pickable():
757757
fig,ax=plt.subplots()
758758
data= (np.arange(200)/200).reshape((2,100))
759759
x,y=data
760-
hb=ax.hexbin(x,y,extent=[.1,.3,.6,.7],picker=-1)
760+
hb=ax.hexbin(x,y,extent=[.1,.3,.6,.7],picker=True,pickradius=-1)
761761
mouse_event=SimpleNamespace(x=400,y=300)
762762
asserthb.contains(mouse_event)[0]
763763

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp