地理熊猫-基于数据框中的种群的颜色

时间:2019-09-13 17:07:49

标签: python dataframe geopandas

对于美国,file具有以下形状文件。

以及以下带有状态名称和填充的数据框 enter image description here

我尝试使用以下代码根据每个州的人口来绘制shapefile并为其着色:

import geopandas as gpd
import geoplot 

fname = "states.json"

us = gpd.read_file(fname)

geoplot.choropleth(
    us, hue=population_mean['POPEST2016_CIV'],
    cmap='Blues', figsize=(8, 4)
)

但是,我似乎没有得到正确的颜色。例如,人口最多的阴影最深。

示例输出:

enter image description here

谢谢

1 个答案:

答案 0 :(得分:0)

更新:

我通过合并解决了

fname = "states.json"
us = gpd.read_file(fname)

us = pd.merge(us, population_mean, on=['STATE_NAME'])
us
gplt.choropleth(
    us, hue=us['POPEST2016_CIV'], projection=geoplot.crs.AlbersEqualArea(),
    edgecolor='black', linewidth=1,
    cmap='Greens', legend=True, legend_kwargs={'loc': 'lower left'},
    scheme='fisher_jenks',

)