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 def f(x,var): return np.sinc(x/var)**2 # this is the routine which calls the function f(x,var) # and plots the variation with respect to var 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(-50, 50, 1001) ax.plot(x, f(x,var), lw=5, alpha=0.4, label=var) 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,var=RangeWidget(10, 100, 10)) the fraunhofer limit x, y = np.linspace(-10,10,101), np.linspace(-10,10,101) z1, z2, z3, z4 = np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101]) a = 0 for i in x: b = 0 for j in y: z1[a][b] = ((np.sinc(20*i/20))**2)*((np.sinc(10*j/20))**2) z2[a][b] = ((np.sinc(20*i/50))**2)*((np.sinc(10*j/50))**2) z3[a][b] = ((np.sinc(20*i/100))**2)*((np.sinc(10*j/100))**2) z4[a][b] = ((np.sinc(20*i/200))**2)*((np.sinc(10*j/200))**2) b += 1 a += 1 a = 0 plt.subplot(221) plt.imshow(z1) plt.xticks([]) plt.title('z = 20') plt.subplot(222) plt.imshow(z2) plt.title('z = 50') plt.xticks([]) plt.subplot(223) plt.imshow(z3) plt.title('z = 100') plt.subplot(224) plt.imshow(z4) plt.title('z = 200') x, y = np.linspace(-10,10,101), np.linspace(-10,10,101) z1, z2, z3, z4 = np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101]) a = 0 for i in x: b = 0 for j in y: z1[a][b] = ((np.sinc(10*i/20))**2)*((np.sinc(10*j/20))**2) z2[a][b] = ((np.sinc(10*i/50))**2)*((np.sinc(10*j/50))**2) z3[a][b] = ((np.sinc(10*i/100))**2)*((np.sinc(10*j/100))**2) z4[a][b] = ((np.sinc(10*i/200))**2)*((np.sinc(10*j/200))**2) b += 1 a += 1 a = 0 plt.subplot(221) plt.imshow(z1) plt.xticks([]) plt.title('z = 20') plt.subplot(222) plt.imshow(z2) plt.title('z = 50') plt.xticks([]) plt.subplot(223) plt.imshow(z3) plt.title('z = 100') plt.subplot(224) plt.imshow(z4) plt.title('z = 200') from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline x = np.linspace(-100,100,201) y = np.linspace(-100,100,201) z = np.zeros([201,201]) xwin = 100 ywin = 100 #def f(xwin,ywin,var): def f(var): a = 0 for i in x: b = 0 for j in y: z[a][b] = ((np.sinc(xwin*i/var))**2)*((np.sinc(ywin*j/var))**2) b += 1 a += 1 return z #def plot(xwin,ywin,var): def plot(var): fig, ax = plt.subplots(figsize=(4, 3), subplot_kw={'axisbg':'#EEEEEE', 'axisbelow':True}) image = f(var) ax.imshow(image) return fig #StaticInteract(plot, xwin = RangeWidget(100, 300, 100), ywin = RangeWidget(100, 300, 100),var=RangeWidget(2000, 10000, 1000)) StaticInteract(plot, var=RangeWidget(200, 2000, 100)) #temp = f(2000) #var = def plot(var): fig, ax = plt.subplots(figsize=(4,3), subplot_kw = {'axisbg' : '#EEEEEE', 'axisbelow':True}) image = f(var) ax.imshow(image) #return var return fig #var = 200 #plt.imshow(plot) StaticInteract(plot,var = RangeWidget(200,4200,2000)) plt.imshow(temp) plt.subplot(221) var = 1000 plt.imshow(f(var)) plt.xticks([]) #plt.title('z = 200') plt.subplot(222) plt.imshow(f(2000)) #plt.title('z = 500') plt.xticks([]) plt.subplot(223) plt.imshow(f(5000)) #plt.title('z = 1000') plt.subplot(224) plt.imshow(f(10000)) #plt.title('z = 2000') plt.imshow(f(10000)) import numpy as np import matplotlib.pyplot as plt %matplotlib inline x, y = np.linspace(-100,100,201), np.linspace(-100,100,201) z = np.zeros([201,201]) xwin = 20 ywin = 0.2 dist = 1000 a = 0 for i in x: b = 0 for j in y: z[a][b] = ((np.sinc(xwin*i/dist))**2)*((np.sinc(ywin*j/dist))**2) b += 1 a += 1 plt.imshow(z) vfrom ipywidgets import StaticInteract, RangeWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline x, y = np.linspace(-100,100,201), np.linspace(-100,100,201) z = np.zeros([201,201]) xwin = 20 ywin = 0.2 #var = 200 def plot(dist): fig, ax = plt.subplots(figsize=(4,3), subplot_kw = {'axisbg' : '#EEEEEE', 'axisbelow':True}) a = 0 for i in x: b = 0 for j in y: z[a][b] = ((np.sinc(xwin*i/dist))**2)*((np.sinc(ywin*j/dist))**2) b += 1 a += 1 ax.imshow(z) return fig StaticInteract(plot, dist = RangeWidget(200,4200,500))