【发布时间】:2019-12-15 11:18:31
【问题描述】:
我发现holoviz panel 是构建数据可视化仪表板的一个非常有趣的解决方案。不幸的是,我在获取节点链接图的 vega 图以在 jupyter 笔记本的面板中工作时遇到一些问题。
相关进口等:
import panelpn.extension()from vega import Vega
我的发现:
- vega 导入在面板外使用时效果很好:从https://vega.github.io/editor/#/examples/vega/force-directed-layout 复制/粘贴的 Vega 规范可视化,因为它应该使用
Vega(spec)(参见屏幕截图 1)。 - 使用
pn.pane.Vega(spec)时,我得到一个空白空间。使用pn.pane.Vega(spec).show()在外部运行可视化并查看源代码,我发现 div 是空的(参见屏幕截图 2)。
非常感谢您对这项工作的任何帮助...
谢谢你, 一月。
- 截图1:screenshot1
- 截图2:screenshot2
这是显示问题的最小脚本:
#!/usr/bin/env python
import panel as pn
from bokeh.plotting import output_notebook
from vega import Vega
pn.extension('vega')
output_notebook()
spec = {
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 400,
"height": 200,
"data": [
{
"name": "table",
"values": [
{"category": "A", "amount": 28},
{"category": "B", "amount": 55},
{"category": "C", "amount": 43}
]
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "table", "field": "category"},
"range": "width"
},
{
"name": "yscale",
"domain": {"data": "table", "field": "amount"},
"range": "height"
}
],
"marks": [
{
"type": "rect",
"from": {"data":"table"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "category"},
"width": {"scale": "xscale", "band": 1},
"y": {"scale": "yscale", "field": "amount"},
"y2": {"scale": "yscale", "value": 0}
},
"update": {
"fill": {"value": "steelblue"}
}
}
}
]
}
Vega(spec) # => shows barchart => OK
pn.Column(pn.panel("## Vega test"),
pn.pane.Vega(spec),
pn.panel("_end of test_"))
# => shows "Vega test", then empty space, the "end of test"
pn.Column(pn.panel("## Vega test"),
pn.panel(spec),
pn.panel("_end of test_"))
# => shows "Vega test", then empty space, the "end of test"
【问题讨论】:
-
你试过 pn.extension('vega') 而不是 pn.extension() 吗?
-
是的。也这样做了,但也没有用...
-
也许 discourse.holoviz.org 上的某个人可以帮助您?但是,如果您可以添加一个最小的代码示例来演示您的确切问题,这也会有所帮助。
-
@SandervandenOord 我在描述中添加了一个最小的脚本。
-
我发现这个例子对我有用:panel.pyviz.org/gallery/links/vega_heatmap_link.html也许你可以根据你的例子调整它?
标签: python jupyter-notebook vega holoviz panel-pyviz