Skip to content

Description:

  • Create data visualizations

Resources:

Source and license:

from bokeh.io import output_notebook
# Show Bokeh plots inside the notebook instead of opening a new browser tab
output_notebook()

Draw a line chart

from bokeh.plotting import figure, show
# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# 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 to the plot
p.line(x, y, legend_label="Temp.", line_width=2)
print(p)
Output
figure(id='p1008', ...)
# show the results
show(p)
Figure drawn by code cell 3

Draw several lines in one chart

from bokeh.plotting import figure, show
# prepare some data
x = [1, 2, 3, 4, 5]
y1 = [6, 7, 2, 4, 5]
y2 = [2, 3, 4, 5, 6]
y3 = [4, 5, 5, 7, 2]
# create a new plot with a title and axis labels
p = figure(title="Multiple line example", x_axis_label="x", y_axis_label="y")
# add multiple renderers
p.line(x, y1, legend_label="Temp.", color="blue", line_width=2)
p.line(x, y2, legend_label="Rate", color="red", line_width=2)
p.line(x, y3, legend_label="Objects", color="green", line_width=2)
show(p)
Figure drawn by code cell 5

Color each point from its value (vectorized colors)

import random
from bokeh.plotting import figure, show
# generate some data (1-10 for x, random values for y)
x = list(range(0, 26))
y = random.sample(range(0, 100), 26)
# generate list of rgb hex colors in relation to y
colors = [f"#{255:02x}{int((value * 255) / 100):02x}{255:02x}" for value in y]
# create new plot
p = figure(
title="Vectorized colors example",
sizing_mode="stretch_width",
max_width=500,
height=250,
)
# add circle and line renderers
line = p.line(x, y, line_color="blue", line_width=1)
circle = p.scatter(x, y, fill_color=colors, line_color="blue", size=15)
# show the results
show(p)
Figure drawn by code cell 6

ganymede is made by Eugo