Guest User

Untitled

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