我使用这个包Python
vincent
地图可视化。我在ipython notebook
工作。在
我用国家FIPS代码(取自here)定义了简单的pandas
DataFrame
。然后我试图用这些FIPS代码用vincent
映射DataFrame
数据,但结果显示的结果无法以任何方式给国家着色。我该怎么做?在
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()
^{pr2}$
它们不会显示,因为您没有正确设置
map_key
。world_countries.topo.json
文件通过3个字母的代码标识国家,在该文件中命名为id
(这对应于page you linked to中名为alpha-3
的字段)。如果您查看the raw data in that json file,可以看到这一点。在另外,在
geo_data
中设置'name': 'countries'
,但在map_key
中,您尝试将其引用为counties
(注意缺少的r
)。很容易犯错误,因为在示例页面中,counties
是他们绘制美国县地图的地方。在如果您更改变量名以使它们引用非空字段-您将得到一个可爱的映射,即数据表中的
country_alpha3
与JSON变量countries
中的id
匹配。在N.B.根据您的代码,只有您有数据的国家才会被绘制出来。如果您希望所有国家的轮廓都被勾勒出来,那么可以添加一个图层,其中所有国家的轮廓都是per the second example here,但是只有那些数据是彩色的。我已经在下面的第二个代码/输出部分中提供了代码更改。在
N.B.2当前值为
my_rate
,颜色对比度不是很明显。试着用[0,0.3,0.7,1.0]
让自己相信这是用不同的颜色。在代码
输出
带轮廓层和数据层的代码(对于有数据的代码为彩色):
^{pr2}$输出(输出层加数据层)
相关问题 更多 >
编程相关推荐