I am using Python vincent map visualization with the use of this package introductory examples. I work in ipython notebook.
I defined simple pandas DataFrame with country FIPS codes (taken from here). Then I tried to map DataFrame data with vincent map by these FIPS codes, but resulted visualization fails to colour countries in any manner. How can I make it work?
country_data_tmp = pd.DataFrame({'country_names' : np.array(['Argentina', 'Armenia', 'Australia', 'Austria']),
'country_FIPS' : np.array(['032', '051', '036', '040']),
'my_rate' : np.array([0.254, 0.3456, 0.26, 0.357])})
country_data_tmp.head()
world_topo = r'world-countries.topo.json'
geo_data = [{'name': 'countries',
'url': world_topo,
'feature': 'world-countries'}]
vis = vincent.Map(data=country_data_tmp,
geo_data=geo_data,
scale=1100,
data_bind='my_rate',
data_key='country_FIPS',
map_key={'counties': 'properties.FIPS'})
vis.display()


They don't display because you have not set the
map_keycorrectly. Theworld_countries.topo.jsonfile identifies the countries by 3 letter code, namedidin that file (this corresponds to the field calledalpha-3in the page you linked to). You can see this if you look at the raw data in that json file.Also, you set
'name': 'countries'ingeo_data, but inmap_keyyou try to reference it ascounties(note the missingr). Easy mistake to make, as it'scountiesin the example page where they're mapping US counties.If you change the variable names so that they reference non-empty fields - you'll get a lovely map as
country_alpha3in your data table matchesidin the JSON variablecountries.N.B. As your code stands, only the countries for which you have data will be plotted. You could add a layer with all country outlines as per the second example here if you want all outlined, but only the ones with data coloured. I've provided changes to the code to do that in the second code / output section below.
N.B. 2 With your current values of
my_ratethe colour contrast is not very noticeable. Try it out with[0,0.3,0.7,1.0]to convince yourself it is colouring them differently.Code
Output
Code with outline layer plus data layer (coloured for those with data):
Output (output layer plus data layer)