public
Last active

Example script to show a bug in pick_event

  • Download Gist
pick_event_bug.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
"""
Clicking the indicated point on the left-hand side causes the indicated point on the top right to
be highlighted. Adding 0.1 to the x-value of the left-hand side one seems to alleviate this
problem -- but not adding 0.01.
"""
 
import numpy as np
import matplotlib.pyplot as plt
 
x = np.array([-0.58178965,
2.83321334,
-1.37832619,
-1.32175584,
-0.50806319,
0.40546511,
0.69314718,
-1.78294884,
-0.98390334,
-0.79728744])
y = np.array([0.10775286,
0.,
-0.22789415,
-0.37623547,
-0.52806743,
0.94979714,
1.25276297,
0.10668414,
-0.03905051,
0.5389965 ])
 
# x[9] += 0.1 # fixes the bug
# x[9] += 0.01 # does not fix the bug
 
def callback(event):
print list(event.ind)
ax = event.artist.axes
ax.plot(x[event.ind],y[event.ind],'bo')
plt.draw()
 
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y,marker='o',color='k',alpha=0.2,linestyle='none',picker=5)
ax.text(x[9],y[9],'click this point...', fontsize=10)
ax.text(x[6],y[6],'...and often this one gets highlighted, too', fontsize=10)
fig.canvas.mpl_connect('pick_event', callback)
plt.show()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.