Bokeh 系列文章传送门:
figure 在 bokeh 绘图中有着重要的作用,今天我们来开始了解 figure 的用法, 希望对大家有所帮助。
本次运行环境为:win7
jupyter notebook
python 3.6
bokeh 0.13.0
Bokeh 中绘图的一般步骤加载 bokeh 库,声明在 notebook 或 html 文件中显示或输出绘制的图表
绘制图表框架 figure()
在 figure 上绘制具体的图形,比如 circle,line,bar等
显示图片,show()
本文主要来介绍 figure() 的基本用法。
首先,加载bokeh库from bokeh.plotting import figure, output_notebook, show
output_notebook()
plot_width, plot_weight
plot_width, plot_weight 可以设置绘图区的宽度和高度。
设置参数值,如下:p = figure(plot_width=400, plot_height = 400)
p.circle([1,2,3,4],[5,6,7,8],size=20, color='red', alpha=0.5)
show(p)
图示如下:
width, weight
width, weight 也可以设置绘图区的宽度和高度。
查看官方文档,用的是 plot_width 和 plot_weight 两个参数,但实际上 width 和 height 也有同样的效果,大家不妨探索下。
代码如下:p = figure(width=400, height = 400)
p.circle([1,2,3,4],[5,6,7,8],size=20, color='red', alpha=0.5)
show(p)
tools
工具可以是以下 value,可以根据实际情况来选择合作的工具使用。
"crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select,save,help"# 工具可以是以下 value,可以根据实际情况来选择合作的工具使用
# tools = "crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select,save,help"
tools = "crosshair,pan,wheel_zoom,reset,save"
p = figure(width=400, height = 400, tools=tools)
p.circle([1,2,3,4],[5,6,7,8],size=20, color='red', alpha=0.5)
show(p)
图示如下: