A simple attempt at making a function like Mathematica's manipulate
in Python
to allow easy instantiation of GUI widgets for tweaking parameters and updating
plots.
Tested with Python 2.7.2, Matplotlib 1.0.1
Say we define a function like sinc
:
def sinc(x,A,f,z):
return A*np.sin(2*np.pi*f*x)/(x**z)
We can then plot the function using the mplot
function in manipulate
:
from manipulate import mplot
mplot(sinc,np.arange(0.01,1,0.01),A=(1,2),f=(1,5),z=(0,1))
plt.xlabel('x')
plt.title(u'A sin(2πf x)/x^z')
We can use the GUI sliders to see how parameter adjustments affect the function: