Determine the relative mouse position on matplotlib canvas

I want to create a custom hover action in matplotlib using the onmove function below. What is the best way to convert existing datapoint values ​​in x and event.x to another coordinate system, such as points, so that I can detect when event.x is at p points of any data point? I know the picker event, but I do not want to use it, because it is based on a click, not a hover.

fig = figure()
ax1 = subplot(111)
x = linspace(0,10,11)
y = x**2
ax1.plot(x,y)
fig.canvas.mpl_connect('motion_notify_event', onmove)
p = 5

def onmove(event):
    if event.inaxes:
    #Detect if mouse was moved within p points of any value in x
+5
source share
1 answer
+3

All Articles