Bokeh 简明教程
Bokeh - WebGL
当必须使用大型数据集来借助 Bokeh 创建可视化时,交互可能会非常慢。为此,可以启用 Web Graphics Library (WebGL) 支持。
When one has to use large datasets for creating visualizations with the help of Bokeh, the interaction can be very slow. For that purpose, one can enable Web Graphics Library (WebGL) support.
WebGL 是一个 JavaScript API,使用 GPU(图形处理单元)在浏览器中渲染内容。此标准化插件在所有现代浏览器中都可用。
WebGL is a JavaScript API that renders content in the browser using GPU (graphics processing unit). This standardized plugin is available in all modern browsers.
要启用 WebGL,你只需将 Bokeh Figure 对象的 output_backend 属性设置为“webgl”。
To enable WebGL, all you have to do is set output_backend property of Bokeh Figure object to ‘webgl’.
fig = figure(output_backend="webgl")
在下面的示例中,我们绘制一个带 10,000 个点的 scatter glyph ,借助 WebGL 支持。
In the following example, we plot a scatter glyph consisting of 10,000 points with the help of WebGL support.
import numpy as np
from bokeh.plotting import figure, show, output_file
N = 10000
x = np.random.normal(0, np.pi, N)
y = np.sin(x) + np.random.normal(0, 0.2, N)
output_file("scatterWebGL.html")
p = figure(output_backend="webgl")
p.scatter(x, y, alpha=0.1)
show(p)