Plotly go.Choroplethmap地图自动缩放至指定区域问题
解决Plotly Choroplethmap印度地图自动缩放定位问题
针对使用go.Choroplethmap绘制印度邦/直辖区热力图时无法自动缩放定位到目标区域的问题,核心修正方案如下:
关键配置调整
- 直接通过
update_geos统一配置地理属性,新版Plotly优先识别该方法的参数,无需在update_layout的geo字段重复设置 - 启用
fitbounds="locations",让地图自动适配所有数据覆盖的区域范围 - 设置
center参数定位到印度地理中心(经度78.9629,纬度20.5937),配合projection_type="mercator"保持常规投影 - 显式设置
visible=True,避免因默认配置异常导致参数不生效
修正后的完整代码
go.Choroplethmap( geojson=states_uts, locations=india['state_ut'], z=india[feature], featureidkey="properties.name", colorscale=px.colors.sequential.Reds, marker={"line": {"width": 0.001, "color": "white"}} ).update_geos( scope="asia", fitbounds="locations", projection_type="mercator", center={"lon":78.9629, "lat": 20.5937}, visible=True )
额外检查项
- 确认
states_uts地理数据采用WGS84坐标系(EPSG:4326),非该坐标系会导致定位偏移 - 保证
india['state_ut']中的名称与geojson的properties.name完全匹配,避免数据关联失败影响范围识别
内容的提问来源于stack exchange,提问作者plotmaster473
相关产品推荐
相关产品推荐

