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
FancyArrowPatch picker fails depending on arrowstyle #8384
The picker of FancyArrowPatch will not work with some arrow styles (see included example). Certain arrow styles will cause the picker to produce a pick event if the user clicks anywhere to the left of the arrow.
Code for reproduction
frommatplotlibimportpyplotaspltfrommatplotlibimportpatchesdefpick_event(event):
print("PICK", event.artist)
defmain():
fig=plt.figure()
axes=fig.add_subplot(111)
axes.set_xlim((0, 10))
axes.set_ylim((0, 10))
arrow=patches.FancyArrowPatch(
(8, 2),
(9, 3),
# Uncommenting this will make the pick event be triggered every time I# click to the left of the arrow.# arrowstyle='-|>',
)
# Same thing happens with arrow.set_picker(True)arrow.set_picker(4)
fig.canvas.mpl_connect('pick_event', pick_event)
axes.add_patch(arrow)
plt.show()
if__name__=='__main__':
main()
Actual outcome
(With the arrowstyle line uncommented)
A pick event is always triggered when clicking to the left of the arrow.
frommatplotlibimportpyplotaspltfrommatplotlibimportpatchespicks= []
defpick_event(event):
picks.append(event)
print("PICK", event.artist, event.mouseevent)
fig=plt.figure()
axes=fig.add_subplot(111)
axes.set_xlim((0, 10))
axes.set_ylim((0, 10))
arrow=patches.FancyArrowPatch(
(8, 2),
(9, 3),
# Uncommenting this will make the pick event be triggered every time I# click to the left of the arrow.# arrowstyle='->',
)
arrow2=patches.FancyArrowPatch(
(8, 7),
(9, 8),
# Uncommenting this will make the pick event be triggered every time I# click to the left of the arrow.arrowstyle='->',
)
# Same thing happens with arrow.set_picker(True)arrow.set_picker(4)
arrow2.set_picker(4)
fig.canvas.mpl_connect('pick_event', pick_event)
axes.add_patch(arrow)
axes.add_patch(arrow2)
plt.show()
defhit_mask(ax, paths):
N, M=200, 200X, Y=np.meshgrid(np.linspace(*ax.get_xlim(), N),
np.linspace(*ax.get_ylim(), M))
res=np.zeros((N, M))
fork, (x, y) inenumerate(zip(X.ravel(),
Y.ravel())):
form, pinenumerate(paths):
ifp.contains_point((x, y), None, .1):
res[np.unravel_index(k, (N, M))] +=2**mim=ax.imshow(res, extent=(X.min(), X.max(), Y.min(), Y.max()),
origin='lower', cmap='Set3')
im.get_cmap().set_under('w')
im.set_clim(vmin=.5)
hit_mask(axes, [arrow.get_path(), arrow2.get_path()])
Sorry the code is messy, this is just what I have been playing with trying to debug this.
I have the same problem (Windows, built from source at 7d6b0c8).
Following your example:
frommatplotlibimportpyplotaspltfrommatplotlibimportpatchesimportnumpyasnppicks= []
defpick_event(event):
picks.append(event)
print("PICK", event.artist, event.mouseevent)
fig=plt.figure()
axes=fig.add_subplot(111)
axes.set_xlim((0, 10))
axes.set_ylim((0, 10))
arrow=patches.FancyArrowPatch(
(8, 2),
(9, 3),
# Uncommenting this will make the pick event be triggered every time I# click to the left of the arrow.# arrowstyle='->',
)
arrow2=patches.FancyArrowPatch(
(8, 7),
(9, 8),
# Uncommenting this will make the pick event be triggered every time I# click to the left of the arrow.arrowstyle='->',
)
# Same thing happens with arrow.set_picker(True)arrow.set_picker(4)
arrow2.set_picker(4)
p=arrow.get_path()
patch=patches.PathPatch(p, facecolor='orange', lw=2)
axes.add_patch(patch)
p=arrow2.get_path()
patch=patches.PathPatch(p, facecolor='orange', lw=2)
axes.add_patch(patch)
fig.canvas.mpl_connect('pick_event', pick_event)
axes.add_patch(arrow)
axes.add_patch(arrow2)
plt.show()
Perhaps the problem is that trying to pick an open patch (such as an open arrow) doesn't make sense? (if a pick is defined as clicking inside the patch)
Does anyone know when, or in which version of Matplotlib, this is likely to be fixed please? This issue is still in v2.2.2 on Windows with the arrowstyle values I really want to use, '->' or '-|>'.
My end-user doesn't like 'wedge', 'fancy' or 'simple'. If this issue isn't going to be fixed for a long time I might write my own picker function for use with '->' or '-|>'.
Activity
phobson commentedon Mar 29, 2017
@lejar thanks for the detailed report and sorry for the slow response. hopefully one of us will be able to take a closer look at this soon.
tacaswell commentedon Mar 30, 2017
Something is clearly wrong with the hit testing...
tacaswell commentedon Mar 30, 2017
Sorry the code is messy, this is just what I have been playing with trying to debug this.
QuLogic commentedon Mar 31, 2017
I think the second path is not closed?
vs.
Note the missing 79/CLOSEPOLY to close the path and the last point doesn't really seem to match the first.
colonelsammy commentedon May 10, 2017
I have the same problem (Windows, built from source at 7d6b0c8).
Following your example:
That second patch really doesn't look right!
dstansby commentedon Jul 29, 2017
Perhaps the problem is that trying to pick an open patch (such as an open arrow) doesn't make sense? (if a pick is defined as clicking inside the patch)
fix FancyArrowPatch picker fails depending on arrowstyle matplotlib#8384
fix FancyArrowPatch picker fails depending on arrowstyle matplotlib#8384
fix FancyArrowPatch picker fails depending on arrowstyle matplotlib#8384
fix FancyArrowPatch picker fails depending on arrowstyle matplotlib#8384
cacti77 commentedon Jul 23, 2018
Does anyone know when, or in which version of Matplotlib, this is likely to be fixed please? This issue is still in v2.2.2 on Windows with the arrowstyle values I really want to use, '->' or '-|>'.
My end-user doesn't like 'wedge', 'fancy' or 'simple'. If this issue isn't going to be fixed for a long time I might write my own picker function for use with '->' or '-|>'.
fix FancyArrowPatch picker fails depending on arrowstyle matplotlib#8384
fix FancyArrowPatch picker fails depending on arrowstyle matplotlib#8384
anntzer commentedon Sep 28, 2019
AFAICT this was fixed by #10776.