Geopandas with log-scale colormap

Viewed 1936

If I have the plot below, how can I turn the colormap/legend into a log-scale?

import geopandas as gpd
import matplotlib.pyplot as plt

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world[(world.pop_est>0) & (world.name!="Antarctica")]
fig, ax = plt.subplots(1, 1)
world.plot(column='pop_est', ax=ax, legend=True)

enter image description here

2 Answers

GeoPandas plots are using matplotlib, so you can use normalization of colormap provided by it. Note than I am also specifying min and max values as mins and maxs of the column I am plotting.

world.plot(column='pop_est', legend=True, norm=matplotlib.colors.LogNorm(vmin=world.pop_est.min(), vmax=world.pop_est.max()), )

map

You can simply plot the log of the value instead of the value itself.

import geopandas as gpd
import matplotlib.pyplot as plt
from numpy import log10

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world[(world.pop_est>0) & (world.name!="Antarctica")]
world['logval'] = log10(world['pop_est'])
fig, ax = plt.subplots(1, 1)
world.plot(column='logval', ax=ax, legend=True)
Related