How to adjust the color bar size in geopandas?

Viewed 215

I've created this map using geopandas, but I can't make the color bar have the same size as the figure.

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://i.stack.imgur.com/a26oJ.png

1 Answers

The colorbars on GeoPandas plots are Matplotlib colorbar objects, so it's worth checking those docs.

Add a legend_kwds option and define the shrink value to change the colorbar's size (this example will shrink it to 50% of the default):

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

Alternatively, change the colorbar's location to put it below the map. You may want to change both the location and the size:

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)
)
Related