如何在geopandas中调整颜色条尺寸?

3
我使用geopandas创建了这张地图,但是我无法使颜色条与图像大小一致。
ax = covid_death_per_millon_geo.plot(column = 'total_deaths_per_million', legend = True, cmap = 'RdYlGn_r', figsize=(20,15))
ax.set_title('Covid deaths per Million', size = 20)
ax.set_axis_off()

https://istack.dev59.com/a26oJ.webp


请查看此链接:https://geopandas.org/en/stable/docs/user_guide/mapping.html。 - r-beginners
1个回答

2
GeoPandas 绘图中的 colorbars 是 Matplotlib 的 colorbar 对象,所以值得查看 这些文档
添加 legend_kwds 选项并定义 shrink 值以更改 colorbar 的大小(此示例将将其缩小到默认值的 50%):
ax = covid_death_per_millon_geo.plot(
    column="total_deaths_per_million",
    legend=True,
    legend_kwds={
        "shrink":.5
    },
    cmap="RdYlGn_r",
    figsize=(20, 15)
)

或者,将色条的位置更改为将其放置在地图下方。您可能需要同时更改位置和大小:

ax = covid_death_per_millon_geo.plot(
    column="total_deaths_per_million",
    legend=True,
    legend_kwds={
        "location":"bottom",
        "shrink":.5
    },
    cmap="RdYlGn_r",
    figsize=(20, 15)
)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接