You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 08:03:14