我发现holoviz panel是构建数据可视化仪表板的非常有趣的解决方案。不幸的是,我在使节点链接图的vega图在jupyter笔记本的面板中工作时遇到一些问题。
相关进口等:
import panel
pn.extension()
from vega import 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"
答案 0 :(得分:0)
因此,结论是这是面板中的错误,并由@philippjfr快速修复: https://github.com/holoviz/panel/issues/872
要执行此操作,您需要为此使用面板0.7.1。
由于此版本尚不可用,您可以使用以下方法安装最新版本的面板:
点安装git + https://github.com/holoviz/panel.git
vega图可以与最新版本的面板一起显示,如下所示:
pn.Column(pn.pane.Vega(spec))
另请参见discourse.holoviz.org上的讨论:
https://discourse.holoviz.org/t/vega-plot-not-displaying-within-a-holoviz-panel-in-jupyter-notebook/49/5