基于数据帧中的总体的Geopandas颜色

2024-09-28 19:29:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下美国的形状文件file。你知道吗

以及以下带有州名称和人口的数据帧 enter image description here

我试着用下面的代码根据每个州的人口来绘制形状文件并给它上色:

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

谢谢


Tags: 文件数据代码import名称as绘制fname
1条回答
网友
1楼 · 发布于 2024-09-28 19:29:21

更新:

我通过合并解决了

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',

)

相关问题 更多 >