Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bokeh.plotting import figure, curdoc
- from bokeh.models import HoverTool, TapTool, BoxZoomTool, BoxSelectTool, PreviewSaveTool, ResetTool
- from bokeh.models.widgets import Panel, Tabs, TextInput, RadioGroup
- from bokeh.models import Range1d, LogAxis, LinearAxis
- from bokeh.client import push_session
- from bokeh.models.sources import ColumnDataSource
- from bokeh.io import vform, hplot
- from bokeh.palettes import Spectral11
- import numpy as np
- tabs = []
- x = np.linspace(-2*np.pi, 2*np.pi, 200)
- colour_list = Spectral11 #[(51, 153, 51) ,(153, 51, 51), (51, 51, 153), (153, 51,153 ), (153, 51, 51)]
- y = 2*x**2 + 7/4.*x - 4
- w = 1/100.* x**3 - x**2 + 45*x + 4
- a = ColumnDataSource(dict(x = x, y = y))
- b = ColumnDataSource(dict(x = x, y = w))
- Tools = "pan,wheel_zoom,box_zoom,reset,hover,previewsave"
- def update_title(new, radio, sources, figure, line_renders):
- active_source = sources[radio.active]
- line_render = line_renders[radio.active]
- factor = float(new)
- x = np.array(active_source.data["x"])
- y = factor*np.array(active_source.data["y"])
- figure.extra_y_ranges = {"second_y": Range1d(start = np.amin(y),
- end = np.amax(y))}
- figure.add_layout(LogAxis(y_range_name = "second_y", axis_label = "Real large"), "right")
- line_render.glyph.line_alpha = 0
- active_source.data = dict(x = x, y = y)
- figure.line("x", "y", source = active_source, y_range_name = "second_y")
- figure_obj = figure(plot_width = 1000, plot_height = 800, title = "these are waves", tools = Tools)
- line_render_one = figure_obj.line("x", "y", source = a, line_width = 2, line_color = colour_list[3])
- line_render_two = figure_obj.line("x", "y", source = b, line_width = 2, line_color = colour_list[1])
- line_renders = [line_render_one, line_render_two]
- text = TextInput(title="title or float", value='my sine wave')
- radio = RadioGroup(labels = ["0", "1"], active = 0)
- text.on_change('value', lambda attr, old, new, radio = radio, sources = (a, b), figure = figure_obj,
- line_renders = line_renders:
- update_title(new, radio, sources, figure_obj, line_renders))
- tabs.append(Panel(child = hplot(figure_obj, vform(text, radio)), title = "two by two"))
- tabs = Tabs(tabs = tabs)
- session = push_session(curdoc())
- session.show()
- session.loop_until_closed()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement