Repository navigation
Description
Bug report
When multiple axes overlap (eg, with legend, inset_axes, or manually placed) mouse events passed to event handler functions will always be for the lower axes coordinates and data. This results in the complete loss of user interactivity with the overlayed axes.
This behaviour did not occur with matplotlib 2.0.1, where event data was correct and overlayed widgets worked as expected.
Code for reproduction
This is the check_buttons.py example, slightly modified to move the check buttons half over the main axes plot. The half of the buttons/labels over the plot do not trigger the check buttons, while the half off the plot do. If using matplotlib 2.0.1, the entire buttons/labels trigger as expected.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons
t = np.arange(0.0, 2.0, 0.01)
s0 = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
s2 = np.sin(6*np.pi*t)
fig, ax = plt.subplots()
l0, = ax.plot(t, s0, visible=False, lw=2)
l1, = ax.plot(t, s1, lw=2)
l2, = ax.plot(t, s2, lw=2)
rax = plt.axes([0.07, 0.15, 0.1, 0.15])
check = CheckButtons(rax, ('2 Hz', '4 Hz', '6 Hz'), (False, True, True))
def func(label):
if label == '2 Hz':
l0.set_visible(not l0.get_visible())
elif label == '4 Hz':
l1.set_visible(not l1.get_visible())
elif label == '6 Hz':
l2.set_visible(not l2.get_visible())
plt.draw()
check.on_clicked(func)
def mouse_click(event):
print(event)
fig.canvas.mpl_connect('button_press_event', mouse_click)
plt.show()Actual outcome
Using Matplotlib 2.1.0, clicking the "2 Hz" box (off plot) or label (over plot):
MPL MouseEvent: xy=(53,125) xydata=(0.128125,0.736111111111) button=1 dblclick=False inaxes=Axes(0.07,0.15;0.1x0.15)
Checkbutton clicked.
MPL MouseEvent: xy=(87,125) xydata=(-0.0686068548387,-0.670238095238) button=1 dblclick=False inaxes=AxesSubplot(0.125,0.11;0.775x0.77)
Expected outcome
Using matplotlib 2.0.1, clicking the "2 Hz" box (off plot) or label (over plot):
Checkbutton clicked.
MPL MouseEvent: xy=(53,124) xydata=(0.128125,0.722222222222) button=1 dblclick=False inaxes=Axes(0.07,0.15;0.1x0.15)
Checkbutton clicked.
MPL MouseEvent: xy=(88,125) xydata=(0.675,0.736111111111) button=1 dblclick=False inaxes=Axes(0.07,0.15;0.1x0.15)
(Note, different ordering of "Clicked" message and event output message. Significant?)
Matplotlib version
- Operating system: Ubuntu 16.04
- Matplotlib version: 2.1.0
- Matplotlib backend (
print(matplotlib.get_backend())): TKAgg (also tried Qt5Agg) - Python version: 3.5.2
- Jupyter version (if applicable): N/A
- Other libraries:
matplotlib installed using either
sudo -H pip3 install matplotlib==2.1.0 or sudo -H pip3 install matplotlib==2.0.1
Activity
anntzer commentedon Oct 13, 2017
Should be fixed by #9389.