Created
October 23, 2010 18:36
-
-
Save daler/642538 to your computer and use it in GitHub Desktop.
Example script to show a bug in pick_event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment