为什么Python Vincent map visuzalization不从数据帧映射数据?

为什么Python Vincent map visuzalization不从数据帧映射数据?,python,vincent,Python,Vincent,我使用的是Pythonvincent地图可视化。我在ipython笔记本上工作 我用国家FIPS代码(取自)定义了简单的pandasDataFrame。然后我尝试用这些FIPS代码映射DataFrame数据与vincent数据,但结果可视化无法以任何方式给国家着色。我怎样才能让它工作 country_data_tmp = pd.DataFrame({'country_names' : np.array(['Argentina', 'Armenia', 'Australia', 'Austria'

我使用的是
Python
vincent
地图可视化。我在
ipython笔记本上工作

我用国家FIPS代码(取自)定义了简单的
pandas
DataFrame
。然后我尝试用这些FIPS代码映射
DataFrame
数据与
vincent
数据,但结果可视化无法以任何方式给国家着色。我怎样才能让它工作

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()


它们不会显示,因为您没有正确设置
map\u键。
world\u countries.topo.json
文件通过该文件中名为
id
的三字母代码标识国家(这对应于文件中名为
alpha-3
的字段)。如果你看的话,你可以看到这个

此外,您在
地理数据
中设置了
'name':'countries'
,但在
地图键
中,您尝试将其引用为
县(请注意缺少的
r
)。很容易犯错误,因为在示例页面中,
是他们绘制美国县地图的地方

如果您更改变量名,使其引用非空字段,您将得到一个可爱的映射,数据表中的
country\u alpha3
与JSON变量
countries
中的
id
匹配

N.B.根据您的代码,将只绘制您拥有数据的国家。您可以添加一个包含所有国家/地区轮廓的图层,就像您希望所有国家/地区轮廓一样,但只能添加带有彩色数据的图层。在下面的第二个代码/输出部分中,我对代码进行了修改

N.B.2使用您当前的
my_rate
值,颜色对比度不是很明显。用
[0,0.3,0.7,1.0]
试试看,让自己相信它给它们涂上了不同的颜色

代码 输出

带轮廓层和数据层的代码(带数据的代码为彩色): 输出(输出层加数据层)

我的回答能让你找到你需要的地方吗?如果您还需要什么,很高兴讨论/澄清。J Richard Snape,非常感谢您的完整回答!这超出了我的预期-我的意思是
countries\u outline
del vis.marks[1].properties.update vis.marks[1].properties.enter.stroke.value='#000'
元素。你知道如何在地图中显示国家名称吗?
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()
#Data setup bit - Input[1] from your notebook
#Note new name for country code country_alpha3

import pandas as pd
import numpy as np

country_data_tmp = pd.DataFrame({'country_names' : np.array(['Argentina', 'Armenia', 'Australia', 'Austria']),
                                 'country_alpha3' : np.array(['ARG','ARM','AUS','AUT']),
                                 'my_rate' : np.array([0.254, 0.3456, 0.26, 0.357])})
country_data_tmp.head()

#map drawing bit Input[2] from your notebook
#Note the changes in variable names

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_alpha3',
                  map_key={'countries': 'id'})

vis.display()
#Replace input[2] with this to add a layer with outline only

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

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

vis = vincent.Map(data=country_data_tmp, 
                  geo_data=geo_data, 
                  scale=100, 
                  data_bind='my_rate', 
                  data_key='country_alpha3',
                  map_key={'countries': 'id'})

del vis.marks[1].properties.update
vis.marks[1].properties.enter.stroke.value = '#000'

vis.display()