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

Skip to content

Commit 8ccffba

Browse files
productivememberofsociety666smheidrich
productivememberofsociety666
authored andcommitted
Added pick methods specific to host and parasite axes.
1 parent c098519 commit 8ccffba

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
@@ -39,6 +39,36 @@ def cla(self):
3939
self.xaxis.set_zorder(2.5)
4040
self.yaxis.set_zorder(2.5)
4141

42+
# Overwritten so events that actually happened in the host axes still count
43+
def pick(self, mouseevent):
44+
"""
45+
call signature::
46+
47+
pick(mouseevent)
48+
49+
each child artist will fire a pick event if *mouseevent* is over
50+
the artist and the artist has picker set
51+
"""
52+
# Pick self
53+
if self.pickable():
54+
picker = self.get_picker()
55+
if six.callable(picker):
56+
inside, prop = picker(self, mouseevent)
57+
else:
58+
inside, prop = self.contains(mouseevent)
59+
if inside:
60+
self.figure.canvas.pick_event(mouseevent, self, **prop)
61+
62+
# Pick children
63+
for a in self.get_children():
64+
# make sure the event happened in the same axes (never happens but
65+
# whatever) or in host axes
66+
ax = getattr(a, 'axes', None)
67+
if mouseevent.inaxes is None or ax is None or \
68+
mouseevent.inaxes == ax or \
69+
(hasattr(mouseevent.inaxes, "parasites") and \
70+
self in mouseevent.inaxes.parasites):
71+
a.pick(mouseevent)
4272

4373
@functools.lru_cache(None)
4474
def parasite_axes_class_factory(axes_class=None):
@@ -266,6 +296,45 @@ def cla(self):
266296
ax.cla()
267297
self._get_base_axes_attr("cla")(self)
268298

299+
# Need to overwrite this so children of parasite axes get picked as well
300+
def pick(self, mouseevent):
301+
"""
302+
call signature::
303+
304+
pick(mouseevent)
305+
306+
each child artist will fire a pick event if *mouseevent* is over
307+
the artist and the artist has picker set
308+
"""
309+
# Pick self
310+
if self.pickable():
311+
picker = self.get_picker()
312+
if six.callable(picker):
313+
inside, prop = picker(self, mouseevent)
314+
else:
315+
inside, prop = self.contains(mouseevent)
316+
if inside:
317+
self.figure.canvas.pick_event(mouseevent, self, **prop)
318+
319+
# Pick children
320+
for a in self.get_children():
321+
# make sure the event happened in the same axes
322+
ax = getattr(a, 'axes', None)
323+
if mouseevent.inaxes is None or ax is None or \
324+
mouseevent.inaxes == ax:
325+
# we need to check if mouseevent.inaxes is None
326+
# because some objects associated with an axes (e.g., a
327+
# tick label) can be outside the bounding box of the
328+
# axes and inaxes will be None
329+
# also check that ax is None so that it traverse objects
330+
# which do no have an axes property but children might
331+
a.pick(mouseevent)
332+
333+
# Pick parasite axes
334+
for a in self.parasites:
335+
a.pick(mouseevent)
336+
337+
269338
def twinx(self, axes_class=None):
270339
"""
271340
create a twin of Axes for generating a plot with a sharex

0 commit comments

Comments
 (0)