Bokeh绘图

 http://bokeh.pydata.org/en/latest

Bokeh

是一个专门针对Web浏览器的呈现功能的交互式可视化Python库。这是Bokeh与其它可视化库最核心的区别。

  • 专门针对Web浏览器的交互式、可视化Python绘图库

  • 可以做出像D3.js简洁漂亮的交互可视化效果,但是使用难度低于D3.js。

  • 独立的HTML文档或服务端程序

  • 可以处理大量、动态或数据流

  • 支持Python (或Scala, R, Julia…)

  • 不需要使用Javascript

Bokeh接口

  • Charts: 高层接口,以简单的方式绘制复杂的统计图

  • Plotting: 中层接口,用于组装图形元素

  • Models: 底层接口,为开发者提供了最大的灵活性

包引用

from bokeh.io import output_notebook, output_file, show
from bokeh.charts import Scatter, Bar, BoxPlot, Chord
from bokeh.layouts import row
import seaborn as sns

# 导入数据
exercise = sns.load_dataset('exercise')

output_notebook()
#output_file('test.html')

 

  • from bokeh.io import output_file 生成.html文档

  • from boken.io import output_notebook 在jupyter中使用

bokeh.charts

http://bokeh.pydata.org/en/latest/docs/reference/charts.html

散点图 Scatter

示例代码:

# 散点图
p = Scatter(data=exercise, x='id', y='pulse', title='exercise dataset')
show(p)

 

运行结果:

柱状图 Bar

示例代码:

# 柱状图
p = Bar(data=exercise, values='pulse', label='diet', stack='kind', title='exercise dataset')
show(p)

 

运行结果:

盒子图 BoxPlot

示例代码:

# 盒子图
box1 = BoxPlot(data=exercise, values='pulse', label='diet', color='diet', title='exercise dataset')
box2 = BoxPlot(data=exercise, values='pulse', label='diet', stack='kind', color='kind', title='exercise dataset')
show(row(box1, box2))

 

运行结果:

弦图 Chord

• 展示多个节点之间的联系

• 连线的粗细代表权重

示例代码:

# 弦图 Chord
chord1 = Chord(data=exercise, source="id", target="kind")
chord2 = Chord(data=exercise, source="id", target="kind", value="pulse")

show(row(chord1, chord2))

 

运行结果:

bokeh.plotting

方框 square, 圆形 circle

示例代码:

from bokeh.plotting import figure
import numpy as np

p = figure(plot_width=400, plot_height=400)
# 方框
p.square(np.random.randint(1,10,5), np.random.randint(1,10,5), size=20, color="navy")

# 圆形
p.circle(np.random.randint(1,10,5), np.random.randint(1,10,5), size=10, color="green")
show(p)

 

运行结果:

更多图形元素参考:http://bokeh.pydata.org/en/latest/docs/reference/plotting.html

转载于:https://www.cnblogs.com/alexzhang92/p/9794373.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值