JupyterLab - Vega 3和Vega-Lite 2 MIME渲染扩展
项目描述
jupyterlab-vega3
A JupyterLab extension for rendering Vega 3 and Vega-Lite 2
Vega 3已弃用。最新版本默认包含JupyterLab。只有当您有与最新版本不兼容的规范时才使用此扩展。
需求
- JupyterLab >= 3.0
安装
pip install jupyterlab-vega3
用法
要在IPython中渲染Vega-Lite输出
from IPython.display import display
display({
"application/vnd.vegalite.v2+json": {
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
{"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
{"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
}
}, raw=True)
使用altair库
import altair as alt
cars = alt.load_dataset('cars')
chart = alt.Chart(cars).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
)
chart
通过元数据提供vega-embed选项
from IPython.display import display
display({
"application/vnd.vegalite.v2+json": {
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
{"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
{"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
}
}, metadata={
"application/vnd.vegalite.v2+json": {
"embed_options": {
"actions": False
}
}
}, raw=True)
通过altair提供vega-embed选项
import altair as alt
alt.renderers.enable('default', embed_options={'actions': False})
cars = alt.load_dataset('cars')
chart = alt.Chart(cars).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
)
chart
要渲染.vl
、.vg
、vl.json
或.vg.json
文件,只需打开它
贡献
开发安装
注意:您需要NodeJS来构建扩展包。
jlpm
命令是JupyterLab附带并安装的yarn的固定版本。您可以使用下面的yarn
或npm
代替jlpm
。
# Clone the repo to your local environment
# Change directory to the jupyterlab-vega3 directory
# Install package in development mode
pip install -e .
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build
您可以在不同的终端同时监视源目录并运行JupyterLab,以监视扩展源的变化并自动重新构建扩展。
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab
在运行监视命令时,每次保存的更改都将立即在本地上构建并提供给您运行的JupyterLab。刷新JupyterLab以在浏览器中加载更改(您可能需要等待几秒钟以重建扩展)。
默认情况下,jlpm run build
命令会为此扩展生成源映射,以便使用浏览器开发者工具更容易地进行调试。要同时为 JupyterLab 核心扩展生成源映射,可以运行以下命令
jupyter lab build --minimize=False
卸载
pip uninstall jupyterlab-vega3
项目详情
下载文件
下载适用于您的平台文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
jupyterlab_vega3-3.3.0.tar.gz (279.1 kB 查看哈希值)
构建分布
jupyterlab_vega3-3.3.0-py3-none-any.whl (259.0 kB 查看哈希值)
关闭
jupyterlab_vega3-3.3.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0e940ea443ffab48ae9e8e240a856a7470713b5640c29e7ddde2ddaacb748d76 |
|
MD5 | 4a3511abc8cbc12b3a51c5f74cb26df7 |
|
BLAKE2b-256 | 61c4f89e7f99fdce25b0270876db35a36b72d9ed3ebb8953e6d647f1a8de60fa |
关闭
jupyterlab_vega3-3.3.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 217defd09b2388cded417b4e0437aaf67c4d926a277194ff3ce63020d3085b1d |
|
MD5 | 2e28612024bbcddd586c5c319f3f27e7 |
|
BLAKE2b-256 | 2585fa3420a09eb65d8d707bed850770f3490be9b8aaaf42428edb1a75eb8018 |