Last active
August 29, 2015 14:16
-
-
Save wrobstory/1398260581236e20dfa3 to your computer and use it in GitHub Desktop.
Widget trait events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.html import widgets | |
toggle = widgets.ToggleButton() | |
def foo(): | |
if toggle.value is True: | |
print("The Toggle is True!") | |
else: | |
print("The Toggle is False!") | |
toggle.on_trait_change(foo) | |
display(toggle) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from random import gauss | |
# This is the idiomatic way to initiatlize Matplotlib for the Jupyter Notebook | |
%matplotlib inline | |
gaussian = [gauss(2, 0.5) for x in range(0, 1000)] | |
bin_count = 10 | |
hist_plot = plt.hist(gaussian, bins=bin_count) | |
select_widget = widgets.Dropdown(value="10", options=["10", "20", "30"]) | |
def change_plot_bins(trait_name, old_bin_ct, new_bin_ct): | |
int_bin_ct = int(new_bin_ct) | |
plt.close("all") | |
hist_plot = plt.hist(gaussian, bins=int_bin_ct) | |
plt.show(hist_plot) | |
select_widget.on_trait_change(change_plot_bins, "value") | |
select_widget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment