Bi-variant interactive function plotting using IPython
Question: I want to plot two functions, say sine and cosine, with different frequencies
--- so the first variable is the function to plot and the second is it
frequency. I want to have a selector widget that selects the function and a
slider that chooses the frequency. Is it possible to achieve this using
`interact` or do I need a more complicated setup?


Answer: Yes, this should be possible with `interact` For further reading there are a
couple of [`example
notebooks`](https://github.com/ipython/ipython/tree/master/examples/Interactive%20Widgets)
in the github repository that can be used as an introduction into interactive
widgets.

    
    
    %matplotlib inline
    from IPython.html import widgets
    import numpy as np
    import matplotlib.pyplot as plt
    
    fun_map = {
        "sin": np.sin,
        "cos": np.cos
    }
    
    func_name = widgets.Dropdown(
        options=['sin', 'cos'],
        value='sin',
        description='Function:',
    )
    
    freq = widgets.FloatSlider(
        min=1,
        max=5,
        value=1,
        description='Parameter:'
    )
    
    def plot_fun(func_name, freq, fun_map):
        f = fun_map[func_name]
        x = np.linspace(0, 2*np.pi, 100)
        plt.plot(x, f(freq * x))
    
    res = widgets.interact(plot_fun, freq=freq, func_name=func_name,
                           fun_map=widgets.fixed(fun_map))
    

This is the result:

![result](http://i.stack.imgur.com/HCSKj.png)

