Description:
- Create data visualizations
Resources:
Source and license:
- Some of these examples are adapted from the Bokeh first steps guide (https://docs.bokeh.org/en/latest/docs/first_steps.html), Copyright (c) Anaconda, Inc., and Bokeh Contributors, licensed under BSD-3-Clause. That code stays under its own license; see THIRD_PARTY_NOTICES.md.
from bokeh.io import output_notebook
# Show Bokeh plots inside the notebook instead of opening a new browser taboutput_notebook()Example 1
Section titled “Example 1”Draw a line chart
from bokeh.plotting import figure, show
# prepare some datax = [1, 2, 3, 4, 5]y = [6, 7, 2, 4, 5]
# create a new plot with a title and axis labelsp = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
# add a line renderer with legend and line thickness to the plotp.line(x, y, legend_label="Temp.", line_width=2)
print(p)figure(id='p1008', ...)# show the resultsshow(p)
Example 2
Section titled “Example 2”Draw several lines in one chart
from bokeh.plotting import figure, show
# prepare some datax = [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 labelsp = figure(title="Multiple line example", x_axis_label="x", y_axis_label="y")
# add multiple renderersp.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)
Example 3
Section titled “Example 3”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 ycolors = [f"#{255:02x}{int((value * 255) / 100):02x}{255:02x}" for value in y]
# create new plotp = figure( title="Vectorized colors example", sizing_mode="stretch_width", max_width=500, height=250,)
# add circle and line renderersline = 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 resultsshow(p)
ganymede is made by Eugo