In [1]:
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

In [2]:
def f(x):
    return x

In [3]:
interact(f, x='Hello World');



In [4]:
@interact(x=True, y=1.0)
def g(x, y):
    return (x, y)



In [5]:
def h(p, q):
    return (p, q)

In [6]:
hh = interact(h, p=5, q=fixed(20));
type(hh)


Out[6]:
function

In [7]:
interact(f, x=widgets.IntSlider(min=-10,max=30,step=1,value=10));



In [8]:
interact(f, x=(0,4));



In [9]:
interact(f, x=(0,8,2));



In [10]:
@interact(x=(0.0,20.0,0.5))
def h(x=5.5):
    return x



In [11]:
interact(f, x=['apples','oranges']);



In [12]:
interact(f, x={'one': 10, 'two': 20});



In [13]:
def f(a, b):
    return a+b

In [14]:
w = interactive(f, a=10, b=20)

In [15]:
type(w)


Out[15]:
ipywidgets.widgets.interaction.interactive

In [16]:
w.children


Out[16]:
(<ipywidgets.widgets.widget_int.IntSlider at 0x7f9da4094780>,
 <ipywidgets.widgets.widget_int.IntSlider at 0x7f9da4094c18>,
 <ipywidgets.widgets.widget_output.Output at 0x7f9da4094cc0>)

In [184]:
from IPython.display import display, clear_output
ww = display.display(w)
w.observe(a,b, 'value')


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-184-e783b461276c> in <module>()
      1 from IPython.display import display, clear_output
----> 2 ww = display.display(w)
      3 w.observe(a,b, 'value')

AttributeError: 'function' object has no attribute 'display'

In [ ]:
from ipywidgets import FloatSlider

In [ ]:
x_widget = FloatSlider(min=0.0, max=10.0, step=0.05)
y_widget = FloatSlider(min=0.5, max=10.0, step=0.05, value=5.0)

#def update_x_range(*args):
 #   x_widget.max = 2.0 * y_widget.value
#y_widget.observe(x_widget, 'value')
#x_widget.observe(y_widget, 'value')

def printer(x, y):
    print(x + y)
interact(printer,x=x_widget, y=y_widget);
#interact(f, a=x_widget, b=y_widget)

In [ ]:
widgets.IntSlider(
    value=7,
    min=0,
    max=10,
    step=1,
    description='Test:',
    disabled=False,
    continuous_update=False,
    orientation='horizontal',
    readout=True,
    readout_format='i',
    slider_color='white'
)

In [ ]:
widgets.Valid(
    value=True,
    description='Valid!',
    disabled=False
)

In [ ]:
widgets.SelectionSlider(
    options=['scrambled', 'sunny side up', 'poached', 'over easy'],
    value='sunny side up',
    description='I like my eggs ...',
    disabled=False,
    continuous_update=False,
    orientation='horizontal',
    readout=True,
#     readout_format='i',
#     slider_color='black'
)

In [ ]:
import datetime
dates = [datetime.date(2015,i,1) for i in range(1,13)]
options = [(i.strftime('%b'), i) for i in dates]
widgets.SelectionSlider(
    options=options,
    index=(0,11),
    description='Months (2015)'
)

In [ ]:
widgets.Label(
    value="$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$",
    placeholder='Some LaTeX',
    description='Some LaTeX',
    disabled=False
)

In [ ]:
widgets.HTMLMath(
    value=r"Some math and <i>HTML</i>: \(x^2\) and $$\frac{x+1}{x-1}$$",
    placeholder='Some HTML',
    description='Some HTML',
    disabled=False
)

In [ ]:
widgets.Controller(
    index=0,
)

In [18]:
ms = widgets.SelectMultiple(
    options=['Apples', 'Oranges', 'Pears'],
    value=['Oranges'],
    #rows=10,
    description='Fruits',
    disabled=False
)
display(ms)



In [23]:
ms.value


Out[23]:
('Apples', 'Oranges', 'Pears')

In [145]:
import traitlets


caption = widgets.Label(value='The values of slider1 and slider2 are synchronized')
sliders1, slider2 = widgets.IntSlider(description='Slider 1'),\
                    widgets.IntSlider(description='Slider 2')
l = traitlets.link((sliders1, 'value'), (slider2, 'value'))
display(caption, sliders1, slider2)


<traitlets.traitlets.link object at 0x7f9d849609b0>

In [149]:
caption = widgets.Label(value='Changes in source values are reflected in target1')
source, target1 = widgets.IntSlider(description='Source'),\
                  widgets.IntSlider(description='Target 1')
dl = traitlets.dlink((source, 'value'), (target1, 'value'))
display(caption, source, target1)


0

In [171]:
dropdown = widgets.Dropdown(options=[1,2,3])
button = widgets.Button(description="click me!")
display(dropdown, button)

def on_value_change(b):
    display(dropdown.value)

button.on_click(on_value_change)


1
2
3

In [172]:
from scipy.stats import chi2
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1)
df = 55
mean, var, skew, kurt = chi2.stats(df, moments='mvsk')
x = np.linspace(chi2.ppf(0.01, df),chi2.ppf(0.99, df), 100)
ax.plot(x, chi2.pdf(x, df),'r-', lw=5, alpha=0.6, label='chi2 pdf')


Out[172]:
[<matplotlib.lines.Line2D at 0x7f9d8488d898>]

In [29]:
rv = chi2(df)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
vals = chi2.ppf([0.001, 0.5, 0.999], df)
np.allclose([0.001, 0.5, 0.999], chi2.cdf(vals, df))


Out[29]:
True

In [173]:
r = chi2.rvs(df, size=1000)
ax.hist(r, normed=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)


Out[173]:
<matplotlib.legend.Legend at 0x7f9d84c4ef60>

In [58]:
squares = list(map(lambda x: x+1, range(10)))

In [59]:
print(squares)


[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

In [185]:
kalddennoget = widgets.IntText()
button_prototypes = widgets.Button(description="Show prototypes")

def cluster_number(b):
    kalddennoget.value = dropdown_prototypes.value
    clear_output()
    display(kalddennoget.value)    

button_prototypes.on_click(cluster_number)

dropdown_prototypes = widgets.Dropdown(
            options = list(map(lambda x: x+1, range(10))),
            value = 1,
            description = "Select Cluster",
            disabled = False
        )

first_line = widgets.HBox((dropdown_prototypes,button_prototypes, kalddennoget))
display(first_line)
kalddennoget.value


5

In [136]:
display(kalddennoget)



In [138]:
kalddennoget.value+1


Out[138]:
5

In [ ]: