http://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html#userguide-quickstart
可以使用conda或者pip安装
conda install boken # 自动安装依赖库和例子
pip install bokeh # 需要自己手动安装依赖库,没有例子
from bokeh.plotting import figure, output_file, show
# 准本数据集
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# 输出静态的html文件
output_file("lines.html")
# 创建figure并设置相关属性
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
# 渲染直线图像
p.line(x, y, legend="Temp.", line_width=2)
# 查看输出结果,会直接打开html
show(p)
import numpy as np
from bokeh.plotting import figure, output_file, show
# 准备数据
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
"#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]
# 输出静态html文件爱呢(with CDN resources)
output_file("color_scatter.html", title="color_scatter.py example", mode="cdn")
TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select"
# 创建画板
p = figure(tools=TOOLS, x_range=(0,100), y_range=(0,100))
# 渲染图形
p.circle(x,y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None)
# 展示结果
show(p)
import numpy as np
from bokeh.layouts import gridplot
from bokeh.plotting import figure, output_file, show
# 准备数据集
N = 100
x = np.linspace(0, 4*np.pi, N)
y0 = np.sin(x)
y1 = np.cos(x)
y2 = np.sin(x) + np.cos(x)
# 输出静态html文件
output_file("linked_panning.html")
# 创建第一个figure对象
s1 = figure(width=250, plot_height=250, title=None)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)
# NEW: 创建第二个figure对象,共享双轴
s2 = figure(width=250, height=250, x_range=s1.x_range, y_range=s1.y_range, title=None)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
# NEW: 创建一个figure对象,共享单轴
s3 = figure(width=250, height=250, x_range=s1.x_range, title=None)
s3.square(x, y2, size=10, color="olive", alpha=0.5)
# NEW: 将所有的figure放到一个figure中
p = gridplot([[s1, s2, s3]], toolbar_location=None)
# 展示最后的结果
show(p)
import numpy as np
from bokeh.plotting import *
from bokeh.models import ColumnDataSource
# 准备数据
N = 300
x = np.linspace(0, 4*np.pi, N)
y0 = np.sin(x)
y1 = np.cos(x)
# 创建静态html对象
output_file("linked_brushing.html")
# NEW: 创建一列共享数据列
source = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1))
# 创建按钮
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select,lasso_select"
# 创建一个画板
left = figure(tools=TOOLS, width=350, height=350, title=None)
left.circle('x', 'y0', source=source)
# 创建另一额画板
right = figure(tools=TOOLS, width=350, height=350, title=None)
right.circle('x', 'y1', source=source)
# 将画板放到同一个画板中
p = gridplot([[left, right]])
# 输出结果
show(p)
使用x_axis_type=”datetime”指定