Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 689ca4d

Browse files
author
productivememberofsociety666
committed
Added pick methods specific to host and parasite axes.
1 parent 950c712 commit 689ca4d

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,36 @@ def cla(self):
5353
self.xaxis.set_zorder(2.5)
5454
self.yaxis.set_zorder(2.5)
5555

56+
# Overwritten so events that actually happened in the host axes still count
57+
def pick(self, mouseevent):
58+
"""
59+
call signature::
60+
61+
pick(mouseevent)
62+
63+
each child artist will fire a pick event if *mouseevent* is over
64+
the artist and the artist has picker set
65+
"""
66+
# Pick self
67+
if self.pickable():
68+
picker = self.get_picker()
69+
if six.callable(picker):
70+
inside, prop = picker(self, mouseevent)
71+
else:
72+
inside, prop = self.contains(mouseevent)
73+
if inside:
74+
self.figure.canvas.pick_event(mouseevent, self, **prop)
75+
76+
# Pick children
77+
for a in self.get_children():
78+
# make sure the event happened in the same axes (never happens but
79+
# whatever) or in host axes
80+
ax = getattr(a, 'axes', None)
81+
if mouseevent.inaxes is None or ax is None or \
82+
mouseevent.inaxes == ax or \
83+
(hasattr(mouseevent.inaxes, "parasites") and \
84+
self in mouseevent.inaxes.parasites):
85+
a.pick(mouseevent)
5686

5787
_parasite_axes_classes = {}
5888
def parasite_axes_class_factory(axes_class=None):
@@ -307,6 +337,45 @@ def cla(self):
307337
#super(HostAxes, self).cla()
308338

309339

340+
# Need to overwrite this so children of parasite axes get picked as well
341+
def pick(self, mouseevent):
342+
"""
343+
call signature::
344+
345+
pick(mouseevent)
346+
347+
each child artist will fire a pick event if *mouseevent* is over
348+
the artist and the artist has picker set
349+
"""
350+
# Pick self
351+
if self.pickable():
352+
picker = self.get_picker()
353+
if six.callable(picker):
354+
inside, prop = picker(self, mouseevent)
355+
else:
356+
inside, prop = self.contains(mouseevent)
357+
if inside:
358+
self.figure.canvas.pick_event(mouseevent, self, **prop)
359+
360+
# Pick children
361+
for a in self.get_children():
362+
# make sure the event happened in the same axes
363+
ax = getattr(a, 'axes', None)
364+
if mouseevent.inaxes is None or ax is None or \
365+
mouseevent.inaxes == ax:
366+
# we need to check if mouseevent.inaxes is None
367+
# because some objects associated with an axes (e.g., a
368+
# tick label) can be outside the bounding box of the
369+
# axes and inaxes will be None
370+
# also check that ax is None so that it traverse objects
371+
# which do no have an axes property but children might
372+
a.pick(mouseevent)
373+
374+
# Pick parasite axes
375+
for a in self.parasites:
376+
a.pick(mouseevent)
377+
378+
310379
def twinx(self, axes_class=None):
311380
"""
312381
call signature::

0 commit comments

Comments
 (0)