You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Annotation.contains and FancyArrow.contains return incorrect values #10875
from pylab import *
from matplotlib.backend_bases import MouseEvent
rcdefaults()
fig, axs = plt.subplots(2)
for i, ax in enumerate(axs):
ax.set(xlim=(0, 1), ylim=(0, 1))
ann = ax.annotate(
"hello", xy=(.4, .4), xytext=(.6, .6), arrowprops={"arrowstyle": "->"})
ax.figure.canvas.draw()
xs = np.linspace(*ax.get_xlim(), 30)
ys = np.linspace(*ax.get_ylim(), 30)
for x in xs:
for y in ys:
event = MouseEvent(
"button_press_event",
ax.figure.canvas,
*ax.transData.transform_point((x, y)))
art = [ann, ann.arrow_patch][i]
ax.plot(x, y, ".", c="g" if art.contains(event)[0] else "r")
plt.show()
Points in green mark (a) in the top plot, points that are "contained" (per artist.contains) in the annotation object; (b) in the bottom plot, points that are "contained" in the arrow patch of the annotation object.
Obviously neither set of contained points is correct. This affects, for example, the points that trigger interactive dragging of the annotation.
Matplotlib version
Operating system:
Matplotlib version: 2.2.1, but also present in 1.5
Activity
QuLogic commentedon Mar 25, 2018
(Partial) duplicate of #8384; maybe fixed by #10776?
anntzer commentedon Mar 25, 2018
#10776 fixes the containment test for the arrow, but not for the annotation (in that case, the whole bbox of {text + arrow} is selected).
TarasKuzyo commentedon Jul 3, 2018
In the case of the annotation
Text.contains(self, event)in
Annotation. containsreturns correct values,matplotlib/lib/matplotlib/text.py
Lines 2098 to 2104 in e09dece
so fixing containment for the arrow
should automatically fix it for the annotation.
dstansby commentedon Apr 22, 2019
Looks like this is fixed on master (using the example code above):
tacaswell commentedon Apr 22, 2019
Also fixed on v3.1.x
timhoffm commentedon May 4, 2019
This is not yet fixed. It should look like this
Which will be fixed by #10776 as mentioned above.