0% found this document useful (0 votes)
30 views2 pages

Bokeh Plotting for Python Users

This document contains 3 code examples demonstrating the use of Bokeh for creating interactive plots and visualizations in Python notebooks. The first example creates a simple line plot. The second adds multiple line and scatter plots with different styles on a log scale axis. The third uses widgets to interactively update a sine wave plot by changing its frequency, amplitude and phase.

Uploaded by

zentropia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Bokeh Plotting for Python Users

This document contains 3 code examples demonstrating the use of Bokeh for creating interactive plots and visualizations in Python notebooks. The first example creates a simple line plot. The second adds multiple line and scatter plots with different styles on a log scale axis. The third uses widgets to interactively update a sine wave plot by changing its frequency, amplitude and phase.

Uploaded by

zentropia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

bokeh-example

May 7, 2019

In [1]: from [Link] 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("[Link]")

# 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


[Link](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
[Link](x, x, legend="y=x")
[Link](x, x, legend="y=x", fill_color="white", size=8)
[Link](x, y0, legend="y=x^2", line_width=3)
[Link](x, y1, legend="y=10^x", line_color="red")
[Link](x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6)
[Link](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 [Link] import push_notebook, show, output_notebook


from [Link] import figure
output_notebook()

x = [Link](0, 2*[Link], 2000)


y = [Link](x)

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


background_fill_color='#efefef')
r = [Link](x, y, color="#8888cc", line_width=1.5, alpha=0.8)

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


if f == "sin": func = [Link]
elif f == "cos": func = [Link]
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