In [ ]:
from ipywidgets import interact, interactive
from IPython.display import display
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
In [ ]:
def func(x):
outcome = 2*x + 4
print('result: ', outcome)
In [ ]:
func(0) #testing the imput
result: 4
In [ ]:
slider = widgets.IntSlider(value= 10, min= 0, max= 20, step=1, description='x') #value is where the curser starts
out= widgets.interactive_output(func, {'x': slider})
ui= widgets.VBox([slider])
display(ui, out)
In [ ]:
def linear_func(slope, intercept):
x= np.linspace(-10, 10, 1000)
plt.ylim(-10, 10)
plt.plot(x, slope*x + intercept, lw=3, color='crimson')
plt.axhline(0, lw=1, color='blue', ls='--')
plt.axvline(0, lw=1, color='blue', ls='--')
plt.grid()
plt.show()
interactive_plot =interactive(linear_func, slope=(-5,5), intercept=(-5, 5))
interactive_plot
In [ ]:
def nonlinear_func(slope, intercept):
x= np.linspace(-10, 10, 100)
plt.ylim(-10, 10)
plt.axvline(0, lw=1, color='black', ls='--')
plt.axhline(0, lw=1, color='black', ls='--')
plt.plot(x, x**2 + slope*x + intercept, lw=3, color='dodgerblue')
plt.grid()
plt.show()
interactive_plot= interactive(nonlinear_func, slope=(-5,5), intercept=(-5, 5))
interactive_plot
In [ ]:
In [ ]:
!jupyter nbconvert --to html bana310_112025.ipynb
[NbConvertApp] Converting notebook bana310_final.ipynb to html [NbConvertApp] WARNING | Alternative text is missing on 14 image(s). [NbConvertApp] Writing 963726 bytes to bana310_final.html