<jupyter_start><jupyter_text>Lissajous-curvesPlot two-dimensional curves (for instances the so-called LIssajous curves) with a prescribed parametrization UseThis notebook plots any parametrized cruve of the form $(x(t), y(t))$ with $t\in[-\pi,\pi]$. Functions $x(t)$ and $y(t)$ must be introduced by the user. The curve is always plotted in the square $[-1,1]\times [-1,1]$.To execute this notebook, please go to the top menu and click on ``Cell -> Run all``----In case of **error** or **warning** messages, please go to the top menu and click on ``Cell -> Run all``<jupyter_code>hide_me
from numpy import *
import matplotlib.pyplot as plt
import ipywidgets as widgets
from IPython.display import display, clear_output
%matplotlib inline

# To prevent automatic figure display when execution of the cell ends
%config InlineBackend.close_figures=False 

time = linspace(-pi, pi, 1000)
plt.ioff()
ax=plt.gca()
plt.plot(time,time,'b')
plt.xlabel('$x(t)$')
plt.ylabel('$y(t)$')
plt.axis('square')
plt.xlim([-1.,1.])
plt.ylim([-1.,1.])
out=widgets.Output()

def plot(t=0):
    ax.lines[0].set_xdata(xfun(time))
    ax.lines[0].set_ydata(yfun(time))
    with out:
        clear_output(wait=True)
        display(ax.figure)
    
# Cells for x(t) and y(t)
x = widgets.Text(
    value='',
    placeholder='x(t)',
    description='Function x(t):',
    disabled=False
)
y = widgets.Text(
    value='',
    placeholder='y(t)',
    description='Function y(t):',
    disabled=False
)

button=widgets.Button(
    description='Plot',
    disabled=False,
    button_style='',
    tooltip='Plot',
    icon='check'
)
vbox=widgets.VBox(children=(out,x,y,button))
display(vbox) 

def on_button_clicked(b):
    xfun = lambda t: eval(x.value)
    yfun = lambda t: eval(y.value)
    ax.lines[0].set_xdata(xfun(time))
    ax.lines[0].set_ydata(yfun(time))
    plt.axis('square')
    plt.xlim([-1.,1.])
    plt.ylim([-1.,1.])
    with out:
        clear_output(wait=True)
        display(ax.figure)
    
button.on_click(on_button_clicked)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15964740450538686, 'fraction_numerical': 0.01028403525954946, 'mean_word_length': 4.1075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '434340', 'license': 'MIT', 'n_tokens_mistral': 765, 'n_tokens_neox': 731, 'n_words': 178, 'path': 'curves_2d.ipynb', 'repo_name': 'maprieto/Lissajous-curves', 'size': '2042'}