python vincent map does not display

749 views Asked by At

I'm trying to use vincent package to visualize my data (in pandas) in jupyter notebook, but have trouble in initial attempt ,here is the code I use (copied from the http://wrobstory.github.io/2013/10/mapping-data-python.html):

import vincent
import pandas

world_topo=r'world-countries.topo.json'

geo_data = [{'name': 'countries',
            'url': world_topo,
            'feature': 'world-countries'}]

vis = vincent.Map(geo_data=geo_data, scale=200)
vis.to_json('vega.json')
vis.display()

After I ran the code, nothing was displayed. I checked the type of the vis:

  vincent.charts.Map

I'm not sure how to proceed here, I appreciate any input on this problem.

2

There are 2 answers

0
AChervony On

Not sure at which point of implementation of this you are.
Assuming you just used pip to install vincent and tried the code in PY IDLE , you might be missing 2 important steps:

AFIK vincent only generates jsons to be presented using Vega via Jupyter notebook. To render with Vega You will need to install:

1) Jupyter and dependencies
2) Vega and dependencies

I was able to do so using these instructions.
Once jupiter launched, a window opens in the browser, I had to choose 'Python3' under 'new', and put code in the prompt on that page.

Alternately you can use this online Vega renderer. Please also see Vega docs

Note that it seems that vincent is not the latest technology for that purpose, their page points to Altair

Also, I noticed that the json that is generated in 'vega.json' from the code you posted, using the original data, does not render anywhere. That's also an issue, probably happens because it uses outdated format, but I am not sure.

I have limited experience with this technology but I was able to get graphs to render, specifically this, and it is also how it looked for me.

0
MissBleu On

I know that this post is old but I found your error and I thought I would answer here to help future users of vincent as it has worked beautifully for me. I am working with the anaconda version of vincent and jupyter notebook.

First, you have to initialize vincent in your notebook

import vincent
vincent.core.initialize_notebook()

and your next problem is that your URL isn't actually pointing anywhere. For the world map topography you need:

world_topo="https://raw.githubusercontent.com/wrobstory/vincent_map_data/master/world-countries.topo.json"

A decent map printed out for me with those two exceptions.