基于行数的等值线地图颜色比例

问题描述

我正在使用 Python 和 Dash 创建一个 Web 应用程序,并使用 ISO_ALPHA 值创建了一个区域分布图。

使用回调我过滤了数据,当然会更新地图,效果很好。但是,我想添加一个色阶,而是基于单元格值,我希望它基于每个国家/地区的行数。这是为了显示每个国家有多少玩家

代码

    #call back to update map
@app.callback(
    Output(component_id='player_map',component_property='figure'),[Input(component_id='select_list',component_property='value')]
)

def display_map(list_selected):
    dff_map = df_map[df_map.band==list_selected]

    fig = px.choropleth(dff_map,locations='iso_alpha',hover_name='iso_alpha')
    fig.update_geos(fitbounds="locations")

    return fig

先谢谢你

enter image description here

解决方法

不确定是否有更有效的方法,但设法找到了一个解决方案(见下文),它将创建一个新列“计数”并根据国家/地区代码的计数添加计数值。

PostStruct

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...