You are on page 1of 2

bokeh-example

May 7, 2019

In [1]: from bokeh.plotting import figure, output_file, output_notebook, show

# prepare some data


x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# output to static HTML file


# output_file("lines.html")

# output to notebook
output_notebook()

# create a new plot with a title and axis labels


p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')

# add a line renderer with legend and line thickness


p.line(x, y, legend="Temp.", line_width=2)

# show the results


show(p)

In [2]: # prepare some data


x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y0 = [i**2 for i in x]
y1 = [10**i for i in x]
y2 = [10**(i**2) for i in x]

# output to static HTML file


output_notebook()

# create a new plot


p = figure(
tools="pan,box_zoom,reset,save",
y_axis_type="log", y_range=[0.001, 10**11], title="log axis example",
x_axis_label='sections', y_axis_label='particles'
)

1
# add some renderers
p.line(x, x, legend="y=x")
p.circle(x, x, legend="y=x", fill_color="white", size=8)
p.line(x, y0, legend="y=x^2", line_width=3)
p.line(x, y1, legend="y=10^x", line_color="red")
p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6)
p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4")

# show the results


show(p)

In [7]: from ipywidgets import interact


import numpy as np

from bokeh.io import push_notebook, show, output_notebook


from bokeh.plotting import figure
output_notebook()

x = np.linspace(0, 2*np.pi, 2000)


y = np.sin(x)

p = figure(title="simple line example", plot_height=300, plot_width=600, y_range=(-5,5)


background_fill_color='#efefef')
r = p.line(x, y, color="#8888cc", line_width=1.5, alpha=0.8)

def update(f, w=1, A=1, phi=0):


if f == "sin": func = np.sin
elif f == "cos": func = np.cos
r.data_source.data['y'] = A * func(w * x + phi)
push_notebook()

show(p, notebook_handle=True)

interact(update, f=["sin", "cos"], w=(0,50), A=(1,10), phi=(0, 20, 0.1))

interactive(children=(Dropdown(description='f', options=('sin', 'cos'), value='sin'), IntSlider

Out[7]: <function __main__.update(f, w=1, A=1, phi=0)>

You might also like