2

我正在使用文森特为美国绘制县级地图。以 2016 年选举的数据为例。然而,它并不适用于加利福尼亚等一些州。我检查了数据,FIPS 代码似乎存在,但仍然显示为空白。任何想法可能会发生什么?我从 topo.json 获得了县级数据。在此处输入图像描述

geo_data_c2 = [{'name': 'counties',
         'url': county_topo,
         'feature': 'us_counties.geo'}]

vis_election_counties = vincent.Map(data=merged, geo_data=geo_data_c2, scale=1000,
              projection='albersUsa', data_bind='per_dem',
              data_key='combined_fips', map_key={'counties': 'properties.FIPS'})



#Change our domain for an even inteager

vis_election_counties.scales['color'].domain = [0,1]
vis_election_counties.legend[![enter image description here][1]][1](title='per_dem')
vis_election_counties.to_json('vega.json')



vis_election_counties.display()
4

1 回答 1

1

前 7 个州的县的 FIPS 代码按字母顺序需要用零填充到 5 个字符。

科罗拉多州阿拉帕霍县的 FIPS 代码为 8005,在https://raw.githubusercontent.com/jgoodall/us-maps/master/topojson/county.topo.json中表示为“08005”

merged['combined_fips'] = merged['combined_fips'].map(lambda i: str(i).zfill(5))
于 2017-05-18T01:57:02.573 回答