<s> from bokeh . io import vplot <EOL> from bokeh . models import ColumnDataSource , DataRange1d , Plot , LinearAxis , Grid , Circle , HoverTool , BoxSelectTool <EOL> from bokeh . models . widgets import DataTable , TableColumn , StringFormatter , NumberFormatter , StringEditor , IntEditor , NumberEditor , SelectEditor <EOL> from bokeh . embed import file_html <EOL> from bokeh . resources import INLINE <EOL> from bokeh . util . browser import view <EOL> from bokeh . sampledata . autompg2 import autompg2 as mpg <EOL> source = ColumnDataSource ( mpg ) <EOL> manufacturers = sorted ( mpg [ "<STR_LIT>" ] . unique ( ) ) <EOL> models = sorted ( mpg [ "<STR_LIT>" ] . unique ( ) ) <EOL> transmissions = sorted ( mpg [ "<STR_LIT>" ] . unique ( ) ) <EOL> drives = sorted ( mpg [ "<STR_LIT>" ] . unique ( ) ) <EOL> classes = sorted ( mpg [ "<STR_LIT:class>" ] . unique ( ) ) <EOL> columns = [ <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = SelectEditor ( options = manufacturers ) , formatter = StringFormatter ( font_style = "<STR_LIT>" ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = StringEditor ( completions = models ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = NumberEditor ( step = <NUM_LIT:0.1> ) , formatter = NumberFormatter ( format = "<STR_LIT>" ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = IntEditor ( ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = IntEditor ( ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = SelectEditor ( options = transmissions ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = SelectEditor ( options = drives ) ) , <EOL> TableColumn ( field = "<STR_LIT:class>" , title = "<STR_LIT>" , editor = SelectEditor ( options = classes ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = IntEditor ( ) ) , <EOL> TableColumn ( field = "<STR_LIT>" , title = "<STR_LIT>" , editor = IntEditor ( ) ) , <EOL> ] <EOL> data_table = DataTable ( source = source , columns = columns , editable = True ) <EOL> plot = Plot ( title = None , x_range = DataRange1d ( ) , y_range = DataRange1d ( ) , plot_width = <NUM_LIT:1000> , plot_height = <NUM_LIT> ) <EOL> plot . add_layout ( LinearAxis ( ) , '<STR_LIT>' ) <EOL> yaxis = LinearAxis ( ) <EOL> plot . add_layout ( yaxis , '<STR_LIT:left>' ) <EOL> plot . add_layout ( Grid ( dimension = <NUM_LIT:1> , ticker = yaxis . ticker ) ) <EOL> cty_glyph = Circle ( x = "<STR_LIT:index>" , y = "<STR_LIT>" , fill_color = "<STR_LIT>" , size = <NUM_LIT:8> , fill_alpha = <NUM_LIT:0.5> , line_alpha = <NUM_LIT:0.5> ) <EOL> hwy_glyph = Circle ( x = "<STR_LIT:index>" , y = "<STR_LIT>" , fill_color = "<STR_LIT>" , size = <NUM_LIT:8> , fill_alpha = <NUM_LIT:0.5> , line_alpha = <NUM_LIT:0.5> ) <EOL> cty = plot . add_glyph ( source , cty_glyph ) <EOL> hwy = plot . add_glyph ( source , hwy_glyph ) <EOL> tooltips = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> cty_hover_tool = HoverTool ( renderers = [ cty ] , tooltips = tooltips + [ ( "<STR_LIT>" , "<STR_LIT>" ) ] ) <EOL> hwy_hover_tool = HoverTool ( renderers = [ hwy ] , tooltips = tooltips + [ ( "<STR_LIT>" , "<STR_LIT>" ) ] ) <EOL> select_tool = BoxSelectTool ( renderers = [ cty , hwy ] , dimensions = [ '<STR_LIT:width>' ] ) <EOL> plot . add_tools ( cty_hover_tool , hwy_hover_tool , select_tool ) <EOL> layout = vplot ( plot , data_table ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> filename = "<STR_LIT>" <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( file_html ( layout , INLINE , "<STR_LIT>" ) ) <EOL> print ( "<STR_LIT>" % filename ) <EOL> view ( filename ) </s>
