[英]Vega plot not displaying within a holoviz panel in jupyter notebook
我發現holoviz 面板是構建數據可視化儀表板的一個非常有趣的解決方案。 不幸的是,我在獲取節點鏈接圖的 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"
所以結論是,這是面板中的一個錯誤,很快被@philippjfr 修復: https : //github.com/holoviz/panel/issues/872
要完成這項工作,您需要面板 0.7.1。
由於此版本尚不可用,您可以使用以下命令安裝最新版本的面板:
pip 安裝 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.