问题
This is the same question as each of these questions, but none of the suggested solutions are working for me.
I'm trying to make a US State map in Python with the Vincent package, as shown in this tutorial. I'm using the Canopy editor. When I run this code, nothing shows up in my console. There are no errors that appear.
- I've placed us_states.topo.json in my Python working directory.
- I updated Canopy and Vincent.
- I'm using vincent.core.initialize_notebook() as well as vis.display() like some other users have suggested.
I have no idea what I'm doing wrong....
import vincent
vincent.core.initialize_notebook()
state_topo = 'us_states.topo.json'
geo_data = [{'name': 'states',
'url': state_topo,
'feature': 'us_states.geo'},
]
vis = vincent.Map(geo_data=geo_data, scale=1000, projection='albersUsa')
vis.to_json('vega.json')
vis.display()
回答1:
If I'm correct Canopy editor can't render Vincent output.
You should use Vincent on the IPython/Jupyter notebook or just output the json to display it on a browser. The code on your example with some minor modifications is:
import vincent
vincent.core.initialize_notebook()
state_topo = "https://raw.githubusercontent.com/wrobstory/vincent_map_data/master/us_states.topo.json"
geo_data = [{'name': 'states',
'url': state_topo,
'feature': 'us_states.geo'}]
vis = vincent.Map(geo_data = geo_data, scale = 500, projection = 'albersUsa')
vis.to_json('vega.json')
vis.display()
And the output in an IPython/Jupyter notebook can be seen in the image below:
BTW, it seems Vincent is not updated and it wouldn't be. So, have a look for alternatives (e.g., Bokeh) if you don't want to use obsolete software.
来源:https://stackoverflow.com/questions/32377569/unable-to-display-vincent-sample-maps-no-suggested-solutions-work