from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline # here we define the function which depends on variables. # one can define functions with as many variables as desired var = 3 def f(x,a,var): return np.sinc((x+a)/var)**2 + np.sinc((x-a)/var)**2 # this is the routine which calls the function f(x,var) # and plots the variation with respect to var def plot(a): fig, ax = plt.subplots(figsize=(4, 3), subplot_kw={'axisbg':'#EEEEEE', 'axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') x = np.linspace(-2, 2, 201) ax.plot(x, f(x,a,b,var), lw=5, alpha=0.4) #ax.set_xlim(-50, 50) #ax.set_ylim(-0.1, 1.1) #ax.legend(loc='upper right') return fig # here we look at the function's dependence on the value of var. # we can add any number of variables var1, var2 in the same way. # the syntax in the RangeWidget is (start, end, increment) StaticInteract(plot,a=RangeWidget(0, 1, 0.1)) from ipywidgets import StaticInteract, RangeWidget import matplotlib.pyplot as plt %matplotlib inline import numpy as np def plot(a): fig, ax = plt.subplots(figsize=(4,3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) ax.grid(color='w',linewidth=2,linestyle=0.4) x = np.linspace(-1,1,101) ax.plot(x,np.sinc(x/a)**2,lw=5,alpha=0.4) return fig StaticInteract(plot,a=RangeWidget(1,5,1)) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline #var = 1 def f(x,a,b): return np.sinc(x+a)**2 + np.sinc(x+b)**2 def plot(a,b): fig, ax = plt.subplots(figsize=(4, 3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') x = np.linspace(-2, 2, 201) ax.plot(x, f(x,a,b), lw=5, alpha=0.4) return fig StaticInteract(plot,a=RangeWidget(0, 10, 1),b=RangeWidget(0, 10, 1)) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline var = 1 def plot(a): fig, ax = plt.subplots(figsize=(4, 3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') x = np.linspace(-2, 2, 201) y = np.sinc((x+a)/var)**2 + np.sinc((x-a)/var)**2 ax.plot(x, y, lw=5, alpha=0.4) return fig StaticInteract(plot,a=RangeWidget(0, 2, 0.1)) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline var = 5 def plot(a): fig, ax = plt.subplots(figsize=(4, 3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) #ax.grid(color='w', linewidth=2, linestyle='solid') #x = np.linspace(-2, 2, 201) image = np.zeros([10,10]) for i in xrange(len(image)): for j in xrange(len(image)): image[i,j] = (np.sinc((i-4.5-a)/var)**2)*(np.sinc((j-4.5)/var)**2) + (np.sinc((i-4.5+a)/var)**2)*(np.sinc((j-4.5)/var)**2) # y = np.sinc((x+a)/var)**2 + np.sinc((x-a)/var)**2 # ax.plot(x, y, lw=5, alpha=0.4) ax.imshow(image) return fig StaticInteract(plot,a=RangeWidget(1, 5, 1)) var = 10 a = 0 image = np.zeros([10,10]) for i in xrange(len(image)): for j in xrange(len(image)): image[i,j] = (np.sinc((i-4.5-a)/var)**2)*(np.sinc((j-4.5)/var)**2) + (np.sinc((i-4.5+a)/var)**2)*(np.sinc((j-4.5)/var)**2) plt.imshow(image) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline #var = 1 def f(x,var): return np.sinc(x-var)**2 def plot(var): fig, ax = plt.subplots(figsize=(4, 3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') x = np.linspace(-2, 2, 201) ax.plot(x, f(x,var), lw=5, alpha=0.4) return fig StaticInteract(plot,var=RangeWidget(1, 10, 1)) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline # here we define the function which depends on variables. # one can define functions with as many variables as desired var = 2 def f(x,a,var): return np.sinc((x-a)/var)**2 + np.sinc((x+a)/var)**2 # this is the routine which calls the function f(x,var) # and plots the variation with respect to var def plot(a): fig, ax = plt.subplots(figsize=(4, 3), subplot_kw={'axisbg':'#EEEEEE', 'axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') x = np.linspace(-1, 1, 201) ax.plot(x, f(x,var1,var2), lw=5, alpha=0.4) #ax.set_xlim(-200, 200) #ax.set_ylim(-0.1, 1.1) #ax.legend(loc='upper right') return fig # here we look at the function's dependence on the value of var. # we can add any number of variables var1, var2 in the same way. # the syntax in the RangeWidget is (start, end, increment) StaticInteract(plot,a=RangeWidget(0.1, 1, 0.1))