Hi matplotlib-users,
I'm trying to make a very simple graphical user interface using the matplotlib
widgets. While doing this I encountered two problems using the CheckButtons
class:
1) It seems like I can't initialize boolean variables prior to using them. The
example below complains that bsub or bwin are referenced before assignment
when I click on the checkbuttons.
#!/usr/bin/env /usr/bin/python
from pylab import *
from matplotlib.widgets import *
def test():
# Initialize values
bsub = False
bwin = False
print bsub,bwin
winax = axes([0.125, 0.025, 0.175, 0.1])
check = CheckButtons(winax, ('Subsample','Window'), (False, False))
def win(label):
if label == 'Subsample': bsub = not bsub
if label == 'Window': bwin = not bwin
check.on_clicked(win)
show()
if __name__ == '__main__': test()
2) How do I make a CheckButtons class with only one button? The example below
fails with a "TypeError: unsubscriptable object".
#!/usr/bin/env /usr/bin/python
from pylab import *
from matplotlib.widgets import *
def test():
# Initialize values
bsub = False
winax = axes([0.125, 0.025, 0.175, 0.1])
check = CheckButtons(winax, ('Subsample'), (False))
def win(label):
if label == 'Subsample': bsub = not bsub
check.on_clicked(win)
show()
if __name__ == '__main__': test()
Kind regards,
Jesper