Advertisement
Guest User

Untitled

a guest
Apr 27th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. from bokeh.plotting import figure, curdoc
  2. from bokeh.models import HoverTool, TapTool, BoxZoomTool, BoxSelectTool, PreviewSaveTool, ResetTool
  3. from bokeh.models.widgets import Panel, Tabs, TextInput, RadioGroup
  4. from bokeh.models import Range1d, LogAxis, LinearAxis
  5. from bokeh.client import push_session
  6. from bokeh.models.sources import ColumnDataSource
  7. from bokeh.io import vform, hplot
  8. from bokeh.palettes import Spectral11
  9.  
  10. import numpy as np
  11.  
  12. tabs = []
  13.  
  14. x = np.linspace(-2*np.pi, 2*np.pi, 200)
  15.  
  16. colour_list = Spectral11 #[(51, 153, 51) ,(153, 51, 51), (51, 51, 153), (153, 51,153 ), (153, 51, 51)]
  17.  
  18.  
  19.  
  20. y = 2*x**2 + 7/4.*x - 4
  21. w = 1/100.* x**3 - x**2 + 45*x + 4
  22.  
  23. a = ColumnDataSource(dict(x = x, y = y))
  24. b = ColumnDataSource(dict(x = x, y = w))
  25.  
  26. Tools = "pan,wheel_zoom,box_zoom,reset,hover,previewsave"
  27.  
  28.  
  29. def update_title(new, radio, sources, figure, line_renders):
  30.  
  31.     active_source = sources[radio.active]
  32.     line_render = line_renders[radio.active]
  33.     factor = float(new)
  34.  
  35.     x = np.array(active_source.data["x"])
  36.     y = factor*np.array(active_source.data["y"])
  37.  
  38.     figure.extra_y_ranges =  {"second_y": Range1d(start = np.amin(y),
  39.                         end = np.amax(y))}
  40.     figure.add_layout(LogAxis(y_range_name = "second_y", axis_label = "Real large"), "right")
  41.    
  42.     line_render.glyph.line_alpha = 0
  43.  
  44.     active_source.data = dict(x = x, y = y)
  45.    
  46.     figure.line("x", "y", source = active_source, y_range_name = "second_y")
  47.  
  48.  
  49. figure_obj = figure(plot_width = 1000, plot_height = 800, title = "these are waves", tools = Tools)
  50.  
  51. line_render_one = figure_obj.line("x", "y", source = a, line_width = 2, line_color = colour_list[3])
  52. line_render_two = figure_obj.line("x", "y", source = b, line_width = 2, line_color = colour_list[1])
  53. line_renders = [line_render_one, line_render_two]
  54.  
  55. text = TextInput(title="title or float", value='my sine wave')
  56. radio = RadioGroup(labels = ["0", "1"], active = 0)
  57.  
  58. text.on_change('value', lambda attr, old, new, radio = radio, sources = (a, b), figure = figure_obj,
  59.                 line_renders = line_renders:
  60.                 update_title(new, radio, sources, figure_obj, line_renders))
  61.  
  62. tabs.append(Panel(child = hplot(figure_obj, vform(text, radio)), title = "two by two"))
  63.  
  64. tabs = Tabs(tabs = tabs)
  65. session = push_session(curdoc())
  66. session.show()
  67. session.loop_until_closed()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement