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

如何在Plotly Python世界地图中移除南极洲?

如何在Plotly Choropleth地图中移除南极洲区域

要去掉地图里的南极洲区域,你可以通过调整Plotly的geo配置实现,以下两种方法都能解决问题:

方法1:使用natural earth投影

这种投影方式默认会隐藏南极洲,同时优化地图的整体显示比例,适合大多数场景:

修改代码中的geo配置部分:

import plotly.graph_objects as go

go.Figure(data=go.Choropleth(
    locations=choc_df['ISO'],
    text=choc_df['company_location'],
    marker_line_color='black',
    marker_line_width=0.5,
    autocolorscale=False,
    colorscale='brbg_r',
    z=choc_df['rating'],
    customdata=choc_df['number'],
    hovertemplate="<br>".join([
        "<b>%{text}</b>",
        "Number of brands: %{customdata}",
        "Rating: %{z}",
    ]) + '<extra></extra>',
), layout=dict(title='Rating',
        geo=dict(
            showcountries=True, 
            countrycolor='#444444', 
            showlakes=False,
            projection=dict(type='natural earth')  # 关键配置:启用natural earth投影
        )
))

方法2:限制显示的纬度范围

如果你想保留原有投影样式,直接通过lataxis.range设定纬度区间,把南极洲(纬度低于-60°的区域)排除在外:

import plotly.graph_objects as go

go.Figure(data=go.Choropleth(
    locations=choc_df['ISO'],
    text=choc_df['company_location'],
    marker_line_color='black',
    marker_line_width=0.5,
    autocolorscale=False,
    colorscale='brbg_r',
    z=choc_df['rating'],
    customdata=choc_df['number'],
    hovertemplate="<br>".join([
        "<b>%{text}</b>",
        "Number of brands: %{customdata}",
        "Rating: %{z}",
    ]) + '<extra></extra>',
), layout=dict(title='Rating',
        geo=dict(
            showcountries=True, 
            countrycolor='#444444', 
            showlakes=False,
            lataxis=dict(range=[-60, 90])  # 关键配置:仅显示纬度-60°到90°的区域
        )
))

两种方案都能有效移除南极洲区域,第一种的地图比例更自然,第二种适合需要保留特定投影的场景。

内容的提问来源于stack exchange,提问作者whatserface

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 01:15:44