我发现holoviz 面板是构建数据可视化仪表板的一个非常有趣的解决方案。不幸的是,我在获取节点链接图的 vega 图以在 jupyter 笔记本的面板中工作时遇到一些问题。
相关进口等:
import panel
pn.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)。
非常感谢您对这项工作的任何帮助......
谢谢你,简。
这是显示问题的最小脚本:
#!/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"