In the case where we want a drop-down that does not necessarily pass a string, a dictionary can be passed, as shown in the following code:
# Dropdowns with dicts
def f(b):
plt.plot(np.arange(0,10), np.power(np.arange(0,10), b))
plt.title("Power Law: $x=ay^b$")
powers = {'one':1, 'two':2, 'three':3}
interact(f, b=powers)
In the following output, we have a dictionary with strings for keys. Here, we are passing an integer to the index of the power law.
For power one, we get the following output:
For power three, we get the following output:
Hence, ipywidgets provides a simple way of going from zero to interactivity in no time. There really isn't an easier way to add interactivity to your Matplotlib plots than by using ipywidgets.