How do you change the label of a matplotlib button on clicking it? Like if I have a matplotlib button with the label "Before", I want to click it and change the label to "After". How do I do this? I feel that I should know this but I really can't find anything on this online or in the documentation.
-
3You capture the click event, then programatically change the label. Event handling here: matplotlib.org/1.3.1/users/event_handling.htmlGerrat– Gerrat2014-05-16 23:11:31 +00:00Commented May 16, 2014 at 23:11
-
2How would you "programmatically change the label"?ndb– ndb2014-05-16 23:28:27 +00:00Commented May 16, 2014 at 23:28
Add a comment
|
1 Answer
assuming this example http://matplotlib.org/1.3.1/examples/widgets/buttons.html
bprev.label="A new Label!" #actually this doesnt work...
I figured this out with next to no knowledge of buttons simply by looking at the docs (really just glancing at them) http://matplotlib.org/1.3.1/api/widgets_api.html#Button
a little more experimentation led me to
bprive.label.set_text("A new label") # works
4 Comments
Joran Beasley
you probably have to have interactive mode on
ion() I think ... or it would not actually update the imagendb
didn't work either. Maybe I'll try something else. Thanks for the answers!
Joran Beasley
@lkloh see edit :P apparently i was wrong initially
Christian Baumann
I needed to call
plt.draw() after for the change to take effect.