Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 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()
Add Comment
Please, Sign In to add comment