Created
March 4, 2015 05:17
-
-
Save wrobstory/9847e7d5cf8da2deef29 to your computer and use it in GitHub Desktop.
Green with envy
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 random import gauss | |
from IPython.display import clear_output | |
from IPython.html import widgets | |
from IPython.utils.traitlets import link | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
%matplotlib inline | |
gaussian = [gauss(2, 0.5) for x in range(0, 1000)] | |
hist_plot = plt.hist(gaussian, bins=10) | |
select_widget = widgets.Select(value="10", options=["10", "20", "30"], | |
height=60) | |
radio_widget = widgets.RadioButtons(value="10", options=["10", "20", "30"]) | |
# Callback function to clear our cell, create a new histogram | |
def change_plot_bins(trait_name, old_bin_ct, new_bin_ct): | |
int_bin_ct = int(new_bin_ct) | |
# Clear the old histogram, maintain cell size for the new | |
clear_output(wait=True) | |
plt.hist(gaussian, int_bin_ct) | |
select_widget.on_trait_change(change_plot_bins, "value") | |
radio_widget.on_trait_change(change_plot_bins, "value") | |
link((select_widget, "value"), (radio_widget, "value")) | |
widgets.HBox(children=[select_widget, radio_widget]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment