python bokeh教程_使用Jupyter Notebook+bokeh绘图入门完整步骤

原标题:使用Jupyter Notebook+bokeh绘图入门完整步骤

Bokeh是一款基于浏览器的交互式绘图工具,在IPython Notebook中具有非常好的表现。

安装anaconda3,单击开始菜单,单击下图红色箭头所指菜单启动Jupyter Notebook:

然后在浏览器中单击下图中红色箭头指向的菜单:

然后在单元格内编写下面的代码:

frombokeh.plotting importfigure, output_file, show

fromrandom importrandrange

# 生成测试数据

x = list(range(1,21))

y = [randrange(1,10) for_ inrange(20)]

output_file('lines.html', title='lines')

p = figure(title='lines', x_axis_label='x', y_axis_label='y')

# 设置图例

p.line(x, y, legend='lines', line_width=2)

show(p)

代码截图为:

单击上图中红色箭头所指,运行代码,生成的图片如下图所示,注意红色方框内有一些工具可以对图片进行缩放、平移或保存。

把代码改为:

frombokeh.plotting importfigure, output_file, show

fromrandom importrandrange

x = list(range(1,21))

y = [randrange(1,10) for_ inrange(20)]

output_file('triangle.html', title='triangle')

p = figure(title='triangle', x_axis_label='x', y_axis_label='y')

p.triangle(x, y, legend='triangle', line_width=2)

show(p)

重新运行代码,得到的图像为:

把代码改为:

frombokeh.plotting importfigure, output_file, show

fromrandom importrandrange

x = list(range(1,21))

y = [randrange(1,10) for_ inrange(20)]

output_file('circle.html', title='circle')

p = figure(title='circle', x_axis_label='x', y_axis_label='y')

p.circle(x, y, legend='circle', line_width=2)

show(p)

重新运行代码,得到的图形为:

责任编辑:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值