数据可视化利器 Bokeh Tutorial

1531784027757500d99eead.jpg


数据可视化利器 Bokeh Tutorial

@(数据科学)[小树枝来了, 帮助, Markdown, 数据分析]

Tutorial Overview

The tutorial is broken into several sections, which are each presented in their own notebook:

https://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html#userguide-quickstart
在线jupyter演示:
https://hub.mybinder.org/user/bokeh-bokeh-notebooks-hlweyrv2/notebooks/tutorial/00%20-%20Introduction%20and%20Setup.ipynb
GitHub:
https://github.com/bokeh/bokeh

What is Bokeh

Bokeh is an interactive visualization library that targets modern web browsers for presentation. It is good for:

  • Interactive visualization in modern browsers
  • Standalone HTML documents, or server-backed apps
  • Expressive and versatile graphics
  • Large, dynamic or streaming data
  • Easy usage from python (or Scala, or R, or...)

And most importantly:

NO JAVASCRIPT REQUIRED

The goal of Bokeh is to provide elegant, concise construction of novel graphics in the style of D3.js, from the comfort of high level languages such as Python, and to extend this capability with high-performance interactivity over very large or streaming datasets. Bokeh can help anyone who would like to quickly and easily create interactive plots, dashboards, and data applications.

示例

# Standard imports 
from bokeh.io import output_notebook, show
output_notebook()

# Plot a complex chart with intearctive hover in a few lines of code

from bokeh.models import ColumnDataSource, HoverTool
from bokeh.plotting import figure
from bokeh.sampledata.autompg import autompg_clean as df
from bokeh.transform import factor_cmap

df.cyl = df.cyl.astype(str)
df.yr = df.yr.astype(str)

group = df.groupby(('cyl', 'mfr'))
source = ColumnDataSource(group)

p = figure(plot_width=800, plot_height=300, title="Mean MPG by # Cylinders and Manufacturer",
           x_range=group, toolbar_location=None, tools="")

p.xgrid.grid_line_color = None
p.xaxis.axis_label = "Manufacturer grouped by # Cylinders"
p.xaxis.major_label_orientation = 1.2

index_cmap = factor_cmap('cyl_mfr', palette=['#2b83ba', '#abdda4', '#ffffbf', '#fdae61', '#d7191c'], 
                         factors=sorted(df.cyl.unique()), end=1)

p.vbar(x='cyl_mfr', top='mpg_mean', width=1, source=source,
       line_color="white", fill_color=index_cmap, 
       hover_line_color="black", hover_fill_color=index_cmap)

p.add_tools(HoverTool(tooltips=[("MPG", "@mpg_mean"), ("Cyl, Mfr", "@cyl_mfr")]))

show(p)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • 老天对她关上了门,却忘了为她打开一扇窗。 菊花是我的初中同学,她在全班乃至全校,是个传奇一般的存在。现在回看初中时...
    王茯苓阅读 2,511评论 85 54
  • 来上海后,周末只要不回家,都会和闺蜜见一面,每次见面的晚上,总要深入讨论下工作、生活、情感种种。前几周因为刚来...
    Elsa蜕变之路阅读 498评论 0 0
  • 时光,犹如握不住的沙,刚拾起一个明媚的春天,一个凛冽的冬天又从瘦削的指缝滑落。 握得越紧,散落得越快。握不住的沙,...
    fxp暗香浮动阅读 259评论 0 1