Bokeh 简明教程

Bokeh - Using Bokeh Subcommands

Bokeh 应用程序提供了一些可从命令行执行的子命令。下表显示了子命令:

The Bokeh application provides a number of subcommands to be executed from command line. Following table shows the subcommands −

1

Html

Create HTML files for one or more applications

2

info

print information of Bokeh server configuration

3

json

Create JSON files for one or more applications

4

png

Create PNG files for one or more applications

5

sampledata

Download the bokeh sample data sets

6

secret

Create a Bokeh secret key for use with Bokeh server

7

serve

Run a Bokeh server hosting one or more applications

8

static

Serve static assets (JavaScript, CSS, images, fonts, etc.) used by BokeJS library

9

svg

Create SVG files for one or more applications

下面的命令为具有 Bokeh 图形的 Python 脚本生成 HTML 文件。

Following command generates a HTML file for Python script having a Bokeh figure.

C:\python37>bokeh html -o app.html app.py

添加 show 选项会自动在浏览器中打开 HTML 文件。同样,Python 脚本使用相应的子命令转换为 PNG、SVG、JSON 文件。

Adding show option automatically opens the HTML file in browser. Likewise, Python script is converted to PNG, SVG, JSON files with corresponding subcommand.

若要显示 Bokeh 服务器信息,请按如下方式使用 info 子命令:

To display information of Bokeh server, use info subcommand as follows −

C:\python37>bokeh info
Python version : 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
IPython version : (not installed)
Tornado version : 6.0.3
Bokeh version : 1.3.4
BokehJS static path : c:\python37\lib\site-packages\bokeh\server\static
node.js version : (not installed)
npm version : (not installed)

为了研究不同类型的绘图,Bokeh 网站 https://bokeh.pydata.org 提供了样本数据集。可通过 sampledata 子命令将它们下载到本地机器。

In order to experiment with various types of plots, Bokeh website https://bokeh.pydata.org makes available sample datasets. They can be downloaded to local machine by sampledata subcommand.

C:\python37>bokeh info

以下数据集下载至 C:\Users\User\.bokeh\data 文件夹:

Following datasets are downloaded in C:\Users\User\.bokeh\data folder −

AAPL.csv                                     airports.csv
airports.json                                CGM.csv
FB.csv                                       gapminder_fertility.csv
gapminder_life_expectancy.csv                gapminder_population.csv
gapminder_regions.csv                        GOOG.csv
haarcascade_frontalface_default.xml          IBM.csv
movies.db                                    MSFT.csv
routes.csv                                   unemployment09.csv
us_cities.json                               US_Counties.csv
world_cities.csv
WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.csv

secret 子命令生成要与 SECRET_KEY 环境变量一起用于 serve 子命令的密钥。

The secret subcommand generates a secret key to be used along with serve subcommand with SECRET_KEY environment variable.