python bokeh模块_Python 绘图 – Bokeh 初探

本文介绍了Python的Bokeh库,一个用于现代浏览器的交互式数据可视化库。主要内容包括Bokeh的目标、安装方法、基本绘图步骤、在Jupyter Notebook中的输出以及Bokeh的基本概念和架构。通过一个简单的line图示例展示了如何使用Bokeh创建和展示图表。
摘要由CSDN通过智能技术生成

背景

想了解一下 python 中的几个绘图工具,及其应用场景。bokeh 为其一.

先放一段 Bokeh 的 Vision:Bokeh is an interactive visualization library that targets modern web browsers for presentation. Its goal is to provide elegant, concise construction of versatile graphics, 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.

焦点词:交互式,高性能,浏览器。

安装

pip install bokeh 或使用镜像 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple bokeh

跑个 demo

基本步骤: 准备数据

确定输出方式:html 文件 或

Jupyter Notebook

建Figure模块(对象):用 bokeh.plotting 模块主要的函数:figure()

画图:glyphs, 比如线形图,圆饼等

如 line

显示或保存图show()

save()

demo 代码:from bokeh.plotting import figure, output_file, show

# prepare some data

x = [1, 2, 3, 4, 5]

y = [6, 7, 2, 4, 5]

# output to static HTML file

output_file("lines.html")

# create a new plot with a title and axis labels

p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')

# add a line renderer with legend and line thickness

p.line(x, y, legend_label="Temp.", line_width=2)

# show the results

show(p)

实际图形就不挂出来了,跑一下代码立刻生成。

输出到 Jupyter Notebook

如果是在 Jupyter Notebook 中,用 output_notebook():from bokeh.io import output_notebook

output_notebook()

理解基本概念Bokeh is an interactive visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics, and affords high-performance interactivity over large or streaming datasets. Bokeh can help anyone who would like to quickly and easily make interactive plots, dashboards, and data applications.

在浏览器中 交互式图表库,interactive 怎么理解呢?

Bokeh Python 库 和 Bokeh 客户端库 BokehJS(有自己的API), 负责浏览器上图形的绘制和 render,所以这些交互式操作有 JS 的支持,这估计是 bokeh 的一大特色。

大致的结构和接口:- 最上层:**BokehJS** render UI and handle UI interactions

|--- Documents

|---Models:

|------plots

|------glyphs

|------widgets

|---Data: 图表所需的数据

|---Widgets: 交互式控件,如 button 等

- 中间层: **boken.plotting**

|---figure() -> Figure Model

- 最底层: **bokeh.models**

References

https://www.jianshu.com/p/e80a4c170121

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值