<jupyter_start><jupyter_text>basic interactive sine waveBased on [ipywidgets documentation](https://ipywidgets.readthedocs.io/en)<jupyter_code># library
from ipywidgets import fixed, interactive, FloatSlider
import matplotlib.pyplot as plt
import numpy as np
# setting widget
amplitude_widget = FloatSlider(min=0, max=5.0, step=0.1, value=1)
frequency_widget = FloatSlider(min=0, max=1, step=0.1, value=0.5)
ylim_widget = FloatSlider(min=0.05, max=10, step=0.05, value=1.25)
x_max = fixed(10)
step = fixed(10)
# function
def sine_wave(amplitude, frequency, ylim, x_max=10, step=10):
    plt.figure('Plot 1')
    x_axis = np.linspace(0, x_max, x_max * step)
    plt.plot(x_axis, amplitude * np.sin(2 * np.pi * frequency * x_axis))
    plt.ylim(ylim, -1 * ylim)
    plt.show()

def update_ylim(*args):
    if amplitude_widget.value >= ylim_widget.min:
        ylim_widget.max = 2 * amplitude_widget.value
    else:
        ylim_widget.max = ylim_widget.min

amplitude_widget.observe(update_ylim, 'value')

widget = interactive(sine_wave, amplitude=amplitude_widget, frequency=frequency_widget, ylim=ylim_widget, x_max=x_max, step=step)
# show
display(widget)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12647554806070826, 'fraction_numerical': 0.03035413153456998, 'mean_word_length': 5.451086956521739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '189434', 'license': 'MIT', 'n_tokens_mistral': 461, 'n_tokens_neox': 443, 'n_words': 89, 'path': 'notebooks/ipywidgets/basic interactive sine wave.ipynb', 'repo_name': 'yasirroni/IPython', 'size': '1186'}