bokeh python

Bokeh is an interactive Python data visualization library which targets modern web browsers for presentation.

Bokeh是一个交互式Python数据可视化库,以现代Web浏览器为对象进行演示。

Python Bokeh library aims at providing high-performing interactivity with the concise construction of novel graphics over very large or even streaming datasets in a quick, easy way and elegant manner.

Python Bokeh库旨在以快速,便捷的方式和优雅的方式,在非常大的甚至是流的数据集上以新颖的图形的简洁结构提供高性能的交互性。

1. Python Bokeh库 (1. Python Bokeh Library)

Bokeh offers simple, flexible and powerful features and provides two interface levels:

Bokeh提供简单,灵活和强大的功能,并提供两个界面级别:

  • Bokeh.models: A low-level interface which provides the application developers with most flexibility.Bokeh.models :一个低级接口,为应用程序开发人员提供了最大的灵活性。
  • Bokeh.plotting: A higher-level interface to compose visual glyphs.Bokeh.plotting :组成可视字形的高级界面。

2.散景依赖 (2. Bokeh Dependencies)

Before beginning with Bokeh, we need to have NumPy installed on our machine.

在开始Bokeh之前,我们需要在计算机上安装NumPy 。

3.安装散景模块 (3. Installing Bokeh Module)

The easiest way to install bokeh and its dependencies is by using conda or pip.

安装bokeh及其依赖项的最简单方法是使用conda或pip 。

To install using conda open the terminal and run the following command:

要使用conda进行安装,请打开终端并运行以下命令:

sudo conda install bokeh

To install using pip open the terminal and run the following command:

要使用pip进行安装,请打开终端并运行以下命令:

sudo pip install bokeh

4.验证Bokeh模块的安装 (4. Verifying Installation of Bokeh Module)

We can verify that Bokeh is correctly installed or not by using some commands. But we will instead make a very small program to provide Bokeh output to verify that it is working properly.

我们可以使用某些命令来验证Bokeh是否已正确安装。 但是,我们将制作一个非常小的程序来提供Bokeh输出以验证其是否正常运行。

from bokeh.plotting import figure, output_file, showoutput_file("test.html")
plot = figure()
plot.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
show(plot)

This should create a file named test.html locally, open that file in browser and see the results like this:

Notice how we were able to create a graph by just using very few lines of code.

这应该在本地创建一个名为test.html的文件,在浏览器中打开该文件,然后看到如下结果:

请注意,我们仅用很少的几行代码就能创建图形。

5. Python散景示例 (5. Python Bokeh Examples)

Now that we have verified Bokeh installation, we can get started with its examples of graphs and plots.

既然我们已经验证了Bokeh的安装,现在就可以开始使用它的图形和绘图示例。

5.1)绘制简单的折线图 (5.1) Plotting a simple line graph)

Plotting a simple line graph is quite similar to what we did for verification, but we are going to add a few details to make the plot easy to read. Let’s look at a code snippet:

绘制简单的折线图与我们进行验证的过程非常相似,但是我们将添加一些细节以使该图易于阅读。 让我们看一下代码片段:

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="Temp.", line_width=2)# show the results
show(p)

Let’s see the output for this program:

With the figure() function and its parameters, we were able to provide titles for the axes as well which is much more descriptive about what data we are presenting on the graph along with the graph legends.

让我们看一下该程序的输出:

借助figure()函数及其参数,我们还能够为轴提供标题,从而更能说明我们在图上显示的数据以及图例。

5.2)多个图 (5.2) Multiple Plots)

We know how to create a simple plot, let’s try creating multiple plots this time. Here is a sample program:

我们知道如何创建一个简单的图,这次我们尝试创建多个图。 这是一个示例程序:

from bokeh.plotting import figure, output_file, show# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y0 = [i**2 for i in x]
y1 = [10**i for i in x]
y2 = [10**(i**2) for i in x]# output to static HTML file
output_file("log_lines.html")# create a new plot
p = figure(tools="pan,box_zoom,reset,save",y_axis_type="log", y_range=[0.001, 10**11], title="log axis example",x_axis_label='sections', y_axis_label='particles'
)# add some renderers
p.line(x, x, legend="y=x")
p.circle(x, x, legend="y=x", fill_color="white", size=8)
p.line(x, y0, legend="y=x^2", line_width=3)
p.line(x, y1, legend="y=10^x", line_color="red")
p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6)
p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4")# show the results
show(p)

Let’s see the output for this program:

These graph plots were much more customised with the legends and line colors. This way, it is easier to differentiate between multiple line plots on the same graph.

让我们看一下该程序的输出:

这些图用图例和线条颜色定制得多。 这样,更容易区分同一图形上的多个折线图。

5.3)矢量化的颜色和大小 (5.3) Vectorized Colors And Sizes)

Different colors and sizes are very important when we need to plot large data as we have a lot to visualize and very few to show. Here is a sample program:

当我们需要绘制大数据时,不同的颜色和大小非常重要,因为我们需要可视化的东西很多,而很少显示。 这是一个示例程序:

import numpy as np
from bokeh.plotting import figure, output_file, show# prepare some data
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = ["#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]# output to static HTML file (with CDN resources)
output_file("color_scatter.html", title="color_scatter.py example", mode="cdn")
TOOLS="crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select"# create a new plot with the tools above, and explicit ranges
p = figure(tools=TOOLS, x_range=(0,100), y_range=(0,100))# add a circle renderer with vectorized colors and sizes
p.circle(x,y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None)# show the results
show(p)

Let’s see the output for this program:

Vectorized graphs are very important in some scenarios, like:

让我们看一下该程序的输出:

矢量化图在某些情况下非常重要,例如:

  • Showing heatmap related data显示热图相关数据
  • Showing data which exhibits the density property of some parameters显示具有某些参数的密度特性的数据

5.4)链接平移和刷 (5.4) Linked panning and brushing)

Linking various aspects is a very useful technique for data visualization. Here is a sample program how this can be achieved with Bokeh:

链接各个方面是用于数据可视化的非常有用的技术。 这是一个示例程序,如何使用Bokeh实现此目的:

import numpy as np
from bokeh.layouts import gridplot
from bokeh.plotting import figure, output_file, show# prepare some data
N = 100
x = np.linspace(0, 4*np.pi, N)
y0 = np.sin(x)
y1 = np.cos(x)
y2 = np.sin(x) + np.cos(x)# output to static HTML file
output_file("linked_panning.html")# create a new plot
s1 = figure(width=250, plot_height=250, title=None)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)# NEW: create a new plot and share both ranges
s2 = figure(width=250, height=250, x_range=s1.x_range, y_range=s1.y_range, title=None)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)# NEW: create a new plot and share only one range
s3 = figure(width=250, height=250, x_range=s1.x_range, title=None)
s3.square(x, y2, size=10, color="olive", alpha=0.5)# NEW: put the subplots in a gridplot
p = gridplot([[s1, s2, s3]], toolbar_location=None)# show the results
show(p)

Let’s see the output for this program:

These kind of plots are especially helpful when we need to show variation of a parameter based on another parameter.

让我们看一下该程序的输出:

当我们需要显示一个参数基于另一个参数的变化时,此类图特别有用。

5.5)日期时间轴 (5.5) Datetime axes)

Plotting with datetime is a very common task. Let’s make an attempt with a sample program:

使用datetime进行绘图是非常常见的任务。 让我们尝试一个示例程序:

import numpy as npfrom bokeh.plotting import figure, output_file, show
from bokeh.sampledata.stocks import AAPL# prepare some data
aapl = np.array(AAPL['adj_close'])
aapl_dates = np.array(AAPL['date'], dtype=np.datetime64)
window_size = 30
window = np.ones(window_size)/float(window_size)
aapl_avg = np.convolve(aapl, window, 'same')# output to static HTML file
output_file("stocks.html", title="stocks.py example")# create a new plot with a a datetime axis type
p = figure(width=800, height=350, x_axis_type="datetime")# add renderers
p.circle(aapl_dates, aapl, size=4, color='darkgrey', alpha=0.2, legend='close')
p.line(aapl_dates, aapl_avg, color='navy', legend='avg')# NEW: customize by setting attributes
p.title.text = "AAPL One-Month Average"
p.legend.location = "top_left"
p.grid.grid_line_alpha=0
p.xaxis.axis_label = 'Date'
p.yaxis.axis_label = 'Price'
p.ygrid.band_fill_color="olive"
p.ygrid.band_fill_alpha = 0.1# show the results
show(p)

Let’s see the output for this program:

让我们看一下该程序的输出:

六,结论 (6. Conclusion)

In this tutorial, we have seen that Bokeh makes it easy to visualize large data and create different graph plots. We have seen examples of different types of graphs. Bokeh makes it easy to visualize data attractively and make it easier to read and understand.

在本教程中,我们已经看到Bokeh可以轻松地可视化大数据并创建不同的图形图。 我们已经看到了不同类型图的示例。 Bokeh使得吸引人的数据可视化变得容易,并且易于阅读和理解。

翻译自: https://www.journaldev.com/19527/bokeh-python-data-visualization

bokeh python

bokeh python_Python Bokeh数据可视化教程相关推荐

  1. 数据可视化教程来了!

    ↑↑↑关注后"星标"Datawhale 每日干货 & 每月组队学习,不错过 Datawhale开源 来自:Datawhale????数据可视化小组 开源初衷 Matplot ...

  2. python用tsne降维图像_python代码实现TSNE降维数据可视化教程

    TSNE降维jne免费资源网 降维就是用2维或3维表示多维数据(彼此具有相关性的多个特征数据)的技术,利用降维算法,可以显式地表现数据.(t-SNE)t分布随机邻域嵌入 是一种用于探索高维数据的非线性 ...

  3. 【Python】数据可视化教程来了!

    来自:Datawhale????数据可视化小组 开源初衷 Matplotlib可以说是python数据可视化最重要且常见的工具之一,几乎每个和数据打交道的人都不可避免,还有大量可视化工具是基于它的二次 ...

  4. 独家 | 使用Gephi设置动态图形动画——在社会网络图中动画化时间动态行为的数据可视化教程...

    作者:Haaya Naushan 翻译:车前子 校对:欧阳锦 本文约3300字,建议阅读7分钟 Gephi可视化Twitter网红的转发行为随时间的变化. 谈到分析社交网络,我之前的文章主要是关于自然 ...

  5. Python Bokeh 库进行数据可视化实用指南

    写在前面 我相信大家已经阅读了不少有关"机器学习"."数据科学家"."数据可视化"等话题的文章.有些人将数据科学称为 21 世纪最性感的工作 ...

  6. 超硬核的 Python 数据可视化教程!

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自:机器学习算法那些事 Python实现可视化的三个步骤: ...

  7. 超硬核的 Python 数据可视化教程

    来源:数据分析1480 本文约3000字,建议阅读6分钟 本文为你介绍Python实现可视化的三个步骤. Python实现可视化的三个步骤: 确定问题,选择图形 转换数据,应用函数 参数设置,一目了然 ...

  8. Python数据可视化教程之基础篇

    点击上方"AI遇见机器学习",选择"星标"公众号 重磅干货,第一时间送达 开运张 | 作者 知乎专栏 | 来源 https://zhuanlan.zhihu.c ...

  9. python数据查询教程_Python数据可视化教程之基础篇

    经过学习之后,我总结了利用python实现可视化的三个步骤: 确定问题,选择图形 转换数据,应用函数 参数设置,一目了然 1 首先,要知道我们用哪些库来画图? matplotlib python中最基 ...

最新文章

  1. 修改Visual Studio Code的自定义键盘快捷键
  2. 一维有限元法matlab,有限元matlab研究.ppt
  3. python带cookie发包demo
  4. [java] JVM监控与调优
  5. HDU1813:Escape from Tetris(IDA)
  6. 也来学学插件式开发续-利用MEF
  7. python基本数据类型和简单用法
  8. 17.3 构建LinuxPC端QT软件上的ARM编译套件并进行测试
  9. 【1+X Web前端等级考证 】| 最新Web前端开发中级实操
  10. java 毕向东 内部类_内部类--毕向东Java基础教程学习笔记
  11. 【强化学习】⚠️手把手带你走进强化学习 3⚠️ OPP 算法实现月球登陆器 (Tensorflow2 版)
  12. 紧急重要四象限软件用哪款便签软件?
  13. ISBN码书籍信息查询
  14. plc的毕业设计冷门题目_PLC毕业设计----PLC毕业设计题目汇总
  15. 惠普HP Deskjet Ink Advantage 3540 打印机驱动
  16. ftp服务器怎么创建文件夹权限设置密码,ftp服务器 创建文件夹权限设置
  17. 使用 vue 开发 APICloud 应用的教程
  18. 2016年7月6日,阿里巴巴集团和上汽联合发布全球首款互联网汽车
  19. github博客迁移——图床搭建
  20. 怪诞行为学中的一些例子

热门文章

  1. [转载] 机器学习 scikit-learn1 预测贷款用户是否会逾期
  2. [转载] Python中numpy.clip();numpy.fabs()的用法;以及math.pow()的说明
  3. Entity Framework 与 面向对象
  4. 02 java多线程基础
  5. 手把手教你写一个java的orm(二)
  6. Ecshop里添加多个h1标题
  7. Fastreport 分组多列排序问题
  8. jni hook java_java通过jni调用hook无效
  9. matlab迭代算法实例_【优化求解】基于NSGA2的求解多目标柔性车间调度算法
  10. qps多少才算高并发_AGV小车价格多少才算合适?