Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions ipywidgets-tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,21 @@
"ax.set_ylim([-4, 4])\n",
"ax.grid(True)\n",
"\n",
"# generate x values\n",
"# generate x values and create placeholder plot\n",
"x = np.linspace(0, 2 * np.pi, 100)\n",
"\n",
"scope = ax.plot(x, x, color='C0')\n",
"\n",
"def my_sine(x, w, amp, phi):\n",
" \"\"\"\n",
" Return a sine for x with angular frequeny w and amplitude amp.\n",
" Return a sine for x with angular frequency w and amplitude amp.\n",
" \"\"\"\n",
" return amp*np.sin(w * (x-phi))\n",
"\n",
"\n",
"@widgets.interact(w=(0, 10, 1), amp=(0, 4, .1), phi=(0, 2*np.pi+0.01, 0.01))\n",
"def update(w = 1.0, amp=1, phi=0):\n",
" \"\"\"Remove old lines from plot and plot new one\"\"\"\n",
" [l.remove() for l in ax.lines]\n",
" ax.plot(x, my_sine(x, w, amp, phi), color='C0')"
"def update(w=1.0, amp=1, phi=0):\n",
" \"\"\"Replace data of plot with new one\"\"\"\n",
" scope[0].set_ydata(my_sine(x, w, amp, phi))\n"
]
},
{
Expand Down