bokeh学习笔记
用 bokeh.plotting
接口创建图表的基本步骤如下:
- 准备一些数据(在上面的例子中,数据是一个简单的Python列表)
- 指定一个输出(在上面的例子中,用
output_file()
函数指定了输出文件名为"lines.html"
) - 调用
figure()
函数创建图表容器并指定一些整体参数,比如title、tools和axes labels - 将数据传入渲染函数(在上面的例子中是
Figure.line
函数)并指定一些视觉参数,比如colors、legends和widths - 调用
show()
或者save()
来显示或保存结果
步骤三、四可以重复使用来绘制多个图形。
- 在使用figure函数创建图表容器时,可以执行的操作:
- 为这个图标命名
- 为坐标轴命名
- 为坐标轴指定范围
- 为坐标轴指定类型
- tools
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'
)
2.p.line() 指定视觉参数
- x与y相对应的值
- line 颜色
- line 形式(有circle、虚线等(可设置参数))
- legend
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")
more examples:
时间序列图形-Datetime axes
Bokeh图形服务器-Bokeh Plot Server