import numpy as np import matplotlib.pyplot as plt from IPython.html import widgets from IPython.html.widgets import interact from IPython.display import display tab1_children = [widgets.ButtonWidget(description="ButtonWidget"), widgets.CheckboxWidget(description="CheckboxWidget"), widgets.DropdownWidget(values=[1, 2], description="DropdownWidget"), widgets.RadioButtonsWidget(values=[1, 2], description="RadioButtonsWidget"), widgets.SelectWidget(values=[1, 2], description="SelectWidget"), widgets.TextWidget(description="TextWidget"), widgets.TextareaWidget(description="TextareaWidget"), widgets.ToggleButtonWidget(description="ToggleButtonWidget"), widgets.ToggleButtonsWidget(values=["Value 1", "Value2"], description="ToggleButtonsWidget"), ] tab2_children = [widgets.BoundedFloatTextWidget(description="BoundedFloatTextWidget"), widgets.BoundedIntTextWidget(description="BoundedIntTextWidget"), widgets.FloatSliderWidget(description="FloatSliderWidget"), widgets.FloatTextWidget(description="FloatTextWidget"), widgets.IntSliderWidget(description="IntSliderWidget"), widgets.IntTextWidget(description="IntTextWidget"), ] tab1 = widgets.ContainerWidget(children=tab1_children) tab2 = widgets.ContainerWidget(children=tab2_children) i = widgets.AccordionWidget(children=[tab1, tab2]) i.set_title(0,"Basic Widgets") i.set_title(1,"Numbers Input") display(i) def factorial(x): print "%s!= %s" % (x,np.math.factorial(x)) def factorial2(x): if type(x) == int: if x >= 0: print np.prod(np.arange(1,x+1)) else: print "ERROR: Number must be positive" else: print "ERROR: Only interger is allowed" factorial(3) i = interact(factorial, x=(0,100)) #This function plot x, y and adds a title def plt_arrays(x, y, title="", color="red", linestyle="dashed", linewidth=2): fig = plt.figure() axes = fig.add_subplot(111) axes.plot(x,y, color=color, linestyle=linestyle, linewidth=linewidth) axes.set_title(title) axes.grid() plt.show() def f(a, b, c, d, **kwargs): x=np.linspace(-10, 10, 20) y = a*(x**3) + b*(x**2) + c*x + d title="$f(x) = (%s)x^{3} + (%s)x^{2} + (%s)x + (%s)$" % (a,b,c,d) plt_arrays(x,y, title=title, **kwargs) #Define Constants a=0.25 b=2 c=-4 d=0 f(a, b, c, d) i = interact(f, a=(-10.,10), b=(-10.,10), c=(-10.,10), d=(-10.,10), color = ["red", "blue", "green"], linestyle=["solid", "dashed"], linewidth=(1,5) ) i.widget