<s> import numpy as np <EOL> import vispy . plot as vp <EOL> from vispy . color import get_colormap <EOL> from vispy . io import load_data_file <EOL> data = np . load ( load_data_file ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> data *= <NUM_LIT:1000> <EOL> dt = <NUM_LIT> <EOL> fig = vp . Fig ( ) <EOL> plt = fig [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> plt . _configure_2d ( ) <EOL> plt . title . text = '<STR_LIT>' <EOL> plt . ylabel . text = '<STR_LIT>' <EOL> plt . xlabel . text = '<STR_LIT>' <EOL> selected = None <EOL> cmap = get_colormap ( '<STR_LIT>' , value = <NUM_LIT:0.5> ) <EOL> colors = cmap . map ( np . linspace ( <NUM_LIT:0.1> , <NUM_LIT> , data . shape [ <NUM_LIT:0> ] ) ) <EOL> t = np . arange ( data . shape [ <NUM_LIT:1> ] ) * ( dt * <NUM_LIT:1000> ) <EOL> for i , y in enumerate ( data ) : <EOL> line = plt . plot ( ( t , y ) , color = colors [ i ] ) <EOL> line . interactive = True <EOL> line . unfreeze ( ) <EOL> line . data_index = i <EOL> line . freeze ( ) <EOL> cursor_text = vp . Text ( "<STR_LIT>" , pos = ( <NUM_LIT:0> , <NUM_LIT:0> ) , anchor_x = '<STR_LIT:left>' , anchor_y = '<STR_LIT>' , <EOL> font_size = <NUM_LIT:8> , parent = plt . view . scene ) <EOL> cursor_line = vp . Line ( parent = plt . view . scene ) <EOL> cursor_symbol = vp . Markers ( pos = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:0> ] ] ) , parent = plt . view . scene ) <EOL> cursor_line . visible = False <EOL> cursor_symbol . visible = False <EOL> cursor_line . order = <NUM_LIT:10> <EOL> cursor_symbol . order = <NUM_LIT:11> <EOL> cursor_text . order = <NUM_LIT:10> <EOL> @ fig . connect <EOL> def on_mouse_press ( event ) : <EOL> global selected , fig <EOL> if event . handled or event . button != <NUM_LIT:1> : <EOL> return <EOL> if selected is not None : <EOL> selected . set_data ( width = <NUM_LIT:1> ) <EOL> selected = None <EOL> for v in fig . visuals_at ( event . pos ) : <EOL> if isinstance ( v , vp . LinePlot ) : <EOL> selected = v <EOL> break <EOL> if selected is not None : <EOL> selected . set_data ( width = <NUM_LIT:3> ) <EOL> update_cursor ( event . pos ) <EOL> @ fig . connect <EOL> def on_mouse_move ( event ) : <EOL> update_cursor ( event . pos ) <EOL> def update_cursor ( pos ) : <EOL> global selected , cursor , data , dt , plt <EOL> if selected is None : <EOL> cursor_text . visible = False <EOL> cursor_line . visible = False <EOL> cursor_symbol . visible = False <EOL> else : <EOL> trace = data [ selected . data_index ] <EOL> tr = fig . scene . node_transform ( selected ) <EOL> pos = tr . map ( pos ) <EOL> x = min ( max ( pos [ <NUM_LIT:0> ] , t [ <NUM_LIT:0> ] ) , t [ - <NUM_LIT:2> ] ) <EOL> ind = x / ( dt * <NUM_LIT:1000> ) <EOL> i = np . floor ( ind ) <EOL> s = ind - i <EOL> y = trace [ i ] * ( <NUM_LIT:1> - s ) + trace [ i + <NUM_LIT:1> ] * s <EOL> cursor_text . text = "<STR_LIT>" % ( x , y ) <EOL> offset = np . diff ( tr . map ( [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:10> , <NUM_LIT:0> ] ] ) , axis = <NUM_LIT:0> ) [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> cursor_text . pos = x + offset , y <EOL> rect = plt . view . camera . rect <EOL> cursor_line . set_data ( np . array ( [ [ x , rect . bottom ] , [ x , rect . top ] ] ) ) <EOL> cursor_symbol . set_data ( pos = np . array ( [ [ x , y ] ] ) , symbol = '<STR_LIT:+>' , <EOL> face_color = '<STR_LIT:b>' ) <EOL> cursor_text . visible = True <EOL> cursor_line . visible = True <EOL> cursor_symbol . visible = True <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> fig . app . run ( ) </s>
