('Austria', 40)
格式
我正在使用vincent将它们绘制到地图上,颜色缩放以表示投票数但不知道如何使用vincent
例如,为代码呈现世界的基本地图
world_topo = r'world-countries.topo.json'
geo_data = [{'name': 'countries',
'url': world_topo,
'feature': 'world-countries'}]
vis = Map(geo_data=geo_data, scale=200)
vis.to_json('vega.json')
但是这只是输出一个JSON,而不是地图的图片,即使这是两个教程示例所说的应该发生的事情(例如:http://wrobstory.github.io/2013/10/mapping-data-python.html和另一个我忘记保存链接的地方)< / p> 有人可以帮帮我吗?在此先感谢你们
答案 0 :(得分:0)
如果你想看到地图的图片,你必须创建一个html文件来读取json文件并映射它。
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js" charset="utf-8"></script>
<script src="http://trifacta.github.com/vega/vega.js"></script>
</head>
<body>
<div id="vis"></div>
//This script will read your json file and print it to the map
<script type="text/javascript">
function parse(spec)
{
vg.parse.spec(spec, function(chart) { chart({el:"#vis"}).update(); });
}
//Put the name of your json file where vega.json is
parse("vega.json");
</script>
</body>
</html>
然后打开命令行并输入:
Python -m SimpleHTTPServer 8000 # Python 2
接下来在http://localhost:8000/path/to/json/file
打开浏览器。
您现在应该在页面上看到地图。请注意,这将是一个基本映射,具体取决于您从json文件传递的数据。
我希望这有帮助并祝你好运!
答案 1 :(得分:0)
First you should change the last line of your code. Try this simplified example:
import vincent
list_data = [10, 20, 30, 20, 15, 30, 45]
vega = vincent.Bar(list_data)
vega.to_json('vega.json',html_out=True,html_path='vega.html')
Then using the terminal CD to the location of your project, i.e. where vega.html is saved.
After that run a local server using Python -m SimpleHTTPServer 8000
. After that you can open any browser and type http://localhost:8000/vega.html .
Note that the depending on the version of vincent the notation inside the .tojson
may be different.
Hope that helps:)
P.S. I think you should add the Python tag as well so people can find it easier.