<jupyter_start><jupyter_text>Spirograph Plot<jupyter_code>%matplotlib widget

import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
def spirograph(n, m,
               rnx=1, rny=1,
               rmx=1, rmy=1,
               kn=1, km=1,
               wn=0, wm=0):
    """
    Generate a spirograph pattern by extruding circles around a central ring.

    Args:
      * n: number of points to generate the central ring with
      * m: number of points to generate each circle with

    Kwargs:
      * rnx: amplitude of central ring x-component
      * rny: amplitude of central ring y-component
      * rmx: amplitude of circles' x-component
      * rmy: amplitude of circles' y-component
      * kn: frequency adjustment of central ring (x and y)
      * km: frequency adjustment of circles (x and y)
      * wn: phase adjustment of central ring (x and y)
      * wm: phase adjustment of circles (x and y)

    Args must be supplied as a single integer value. Kwargs can be supplied either
    as a single numeric value or an array that can be broadcast to the shape (n, m).

    """
    t_ring = np.linspace(0, 2*np.pi, n*m)
    t_circle = np.linspace(0, 2*np.pi, m)
    
    x_ring = rnx * np.sin(t_ring*kn).reshape(n, m)
    y_ring = rny * np.cos(t_ring*kn).reshape(n, m)
    xp = rmx * np.sin(t_circle*km) + x_ring
    yp = rmy * np.cos(t_circle*km) + y_ring

    return xp.reshape(-1), yp.reshape(-1)
def update_plot(n, m, rn, rm):
    """Update the plot from a new set of input values."""
    xp, yp = spirograph(n, m, rnx=rn, rny=rn, rmx=rm, rmy=rm)
    spiro.set_data(xp, yp)

def on_value_change(change):
    """Callback function to trigger an update of the plot when a slider value changes."""
    update_plot(set_n.value, set_m.value, set_rn.value, set_rm.value)
n = 50
m = 25
rn = 4.0
rm = 2.0

x, y = spirograph(n, m, rnx=rn, rny=rn, rmx=rm, rmy=rm)<jupyter_output><empty_output><jupyter_text>SlidersUse these sliders to control the plot drawn below.<jupyter_code>set_n = widgets.IntSlider(value=n, min=10, max=100, step=5,
                          description='n:', continuous_update=False)
set_n.observe(on_value_change, names='value')  # Bind each slider to the callback function.

set_m = widgets.IntSlider(value=m, min=5, max=50, step=1,
                          description='m:', continuous_update=False)
set_m.observe(on_value_change, names='value')

set_rn = widgets.FloatSlider(value=rn, min=0.1, max=6.0, step=0.1,
                             description='rn:', continuous_update=False)
set_rn.observe(on_value_change, names='value')

set_rm = widgets.FloatSlider(value=rm, min=0.1, max=5.0, step=0.1,
                             description='rm:', continuous_update=False)
set_rm.observe(on_value_change, names='value')

sbox = widgets.VBox([set_n, set_m, set_rn, set_rm])
sbox<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>fig = plt.figure(figsize=(8, 8))
fig.canvas.header_visible = False
fig.canvas.footer_visible = False

ax = plt.axes(aspect='equal')
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)

spiro, = ax.plot(x, y)
rmp = 3
update_plot(n, m, rn, rmp)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12191260291323623, 'fraction_numerical': 0.01741608613046232, 'mean_word_length': 3.2862957937584802, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '642803', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1159, 'n_words': 310, 'path': 'examples/voila/voila_spirograph.ipynb', 'repo_name': 'informatics-lab/dashboarding-examples', 'size': '3158'}