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

如何在GeoPandas Pyplot图例中添加千分符或显示百万单位?

解决GeoPandas图例数值格式化问题

1. 显示带千分符的数值(100,000,000)

直接修改legend_kwds中的format参数,使用Python千分符格式化语法即可实现:

df_test.plot(
             ax=ax,
             zorder=1,
             cax=cax,
             column='tax',
             cmap='YlOrRd',
             legend=True,
             legend_kwds={'label': '(USD)',
                          'orientation': "vertical",
                          'pad': 0.3,
                          'format': '{:,.0f}'},  # 替换为千分符格式
);

2. 显示百万单位格式(100mill)

自定义一个格式化函数,将数值转换为百万单位后拼接后缀,再传入format参数:

def format_millions(x):
    # 将数值转换为百万单位并拼接后缀
    return f'{int(x / 1000000)}mill'

df_test.plot(
             ax=ax,
             zorder=1,
             cax=cax,
             column='tax',
             cmap='YlOrRd',
             legend=True,
             legend_kwds={'label': '(USD)',
                          'orientation': "vertical",
                          'pad': 0.3,
                          'format': format_millions},  # 传入自定义格式化函数
);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 16:10:29