<s> from math import pi <EOL> import numpy as np <EOL> from bokeh . client import push_session <EOL> from bokeh . driving import cosine <EOL> from bokeh . models . widgets import Button <EOL> from bokeh . plotting import figure , curdoc , vplot , hplot <EOL> x = np . linspace ( <NUM_LIT:0> , <NUM_LIT:4> * pi , <NUM_LIT:100> ) <EOL> y = np . sin ( x ) <EOL> p = figure ( ) <EOL> r1 = p . line ( [ <NUM_LIT:0> , <NUM_LIT:4> * pi ] , [ - <NUM_LIT:1> , <NUM_LIT:1> ] , color = "<STR_LIT>" ) <EOL> r2 = p . line ( x , y , color = "<STR_LIT>" , line_width = <NUM_LIT:4> ) <EOL> session = push_session ( curdoc ( ) ) <EOL> def start_handler ( ) : <EOL> global playing <EOL> if not playing : <EOL> curdoc ( ) . add_periodic_callback ( update , <NUM_LIT:50> ) <EOL> playing = True <EOL> def stop_handler ( ) : <EOL> global playing <EOL> if playing : <EOL> curdoc ( ) . remove_periodic_callback ( update ) <EOL> playing = False <EOL> button_start = Button ( label = "<STR_LIT>" , button_type = "<STR_LIT:success>" ) <EOL> button_start . on_click ( start_handler ) <EOL> button_stop = Button ( label = "<STR_LIT>" , button_type = "<STR_LIT>" ) <EOL> button_stop . on_click ( stop_handler ) <EOL> controls = hplot ( button_start , button_stop ) <EOL> layout = vplot ( controls , p ) <EOL> @ cosine ( w = <NUM_LIT> ) <EOL> def update ( step ) : <EOL> if playing : <EOL> r2 . data_source . data [ "<STR_LIT:y>" ] = y * step <EOL> r2 . glyph . line_alpha = <NUM_LIT:1> - <NUM_LIT> * abs ( step ) <EOL> playing = True <EOL> curdoc ( ) . add_periodic_callback ( update , <NUM_LIT:50> ) <EOL> session . show ( ) <EOL> session . loop_until_closed ( ) </s>
