Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from matplotlib.widgets import CheckButtons
  3.  
  4. x = range(0, 11)
  5. y1 = [10] * 11
  6. y2 = [20] * 11
  7. y3 = [30] * 11
  8.  
  9. fig, ax = plt.subplots()
  10. p1, = ax.plot(x, y1, color='red', label='red')
  11. p2, = ax.plot(x, y2, color='blue', label='blue', visible=False)
  12. p3, = ax.plot(x, y3, color='green', label='green', visible=False)
  13. lines = [p1, p2, p3]
  14.  
  15. plt.axis([-2.5, 12, 0, 40])
  16. plt.subplots_adjust(left=0.25, bottom=0.1, right=0.95, top=0.95)
  17.  
  18.  
  19. # checkbuton widget
  20. labels = ['red', 'blue', 'green']
  21. activated = [True, False, False]
  22. axCheckButton = plt.axes([0.03, 0.4, 0.15, 0.15])
  23. chxbox = CheckButtons(axCheckButton, labels, activated)
  24.  
  25. def set_visible(label):
  26. index = labels.index(label)
  27. lines[index].set_visible(not lines[index].get_visible())
  28. plt.draw()
  29.  
  30. chxbox.on_clicked(set_visible)
  31.  
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement