本文介绍了如何在Google Colab中显示Vega可视化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Altair在Google Colab中显示Vega-Lite可视化效果.但是有没有办法显示简单的Vega可视化效果?

我在Google Colab中尝试了

I can use Altair to show Vega-Lite visualizations in Google Colab. But is there a way to show plain Vega visualizations?

I tried ipyvega in Google Colab. But when I run their example in Google Colab, then nothing shows up, and there is no error.

解决方案

You can display a vega chart in Colab using the altair.vega.Vega class, once you have enabled the Colab renderer.

Here is an example:

from urllib import request
import json
with request.urlopen("https://vega.github.io/vega/examples/bar-chart.vg.json") as f:
  spec = json.load(f)

from altair import vega
vega.renderers.enable('colab')
vega.Vega(spec)

这篇关于如何在Google Colab中显示Vega可视化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 19:46