Guest User

Untitled

a guest
Dec 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. from matplotlib import pyplot as plt
  2.  
  3. fig, ax = plt.subplots()
  4. x=1
  5.  
  6. def annotate():
  7. global x
  8. if x==1:
  9. x=-1
  10. else:
  11. x=1
  12. ax.annotate(x, (0.5,0.5), textcoords='data', size=10)
  13. ax.annotate('Other annotation', (0.5,0.4), textcoords='data', size=10)
  14.  
  15. def onclick(event):
  16. annotate()
  17. fig.canvas.draw()
  18.  
  19. cid = fig.canvas.mpl_connect('button_press_event',onclick)
  20.  
  21. from matplotlib import pyplot as plt
  22.  
  23. fig, ax = plt.subplots()
  24. x=1
  25. annotation = ax.annotate('', (0.5,0.5), textcoords='data', size=10) # empty annotate object
  26. other_annotation = ax.annotate('Other annotation', (0.5,0.4), textcoords='data', size=10) # other annotate
  27.  
  28. def annotate():
  29. global x
  30. if x==1:
  31. x=-1
  32. else:
  33. x=1
  34. annotation.set_text(x)
  35.  
  36.  
  37. def onclick(event):
  38. annotate()
  39. fig.canvas.draw()
  40.  
  41. cid = fig.canvas.mpl_connect('button_press_event',onclick)
  42. plt.show()
Add Comment
Please, Sign In to add comment