具有对数比例色图的 Geopandas
Geopandas with log-scale colormap
如果我有下面的图,我怎样才能把 colormap/legend 变成对数刻度?
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)
您可以简单地绘制值的对数而不是值本身。
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)
GeoPandas 绘图使用 matplotlib,因此您可以使用它提供的色图标准化。请注意,我还将最小值和最大值指定为我正在绘制的列的最小值和最大值。
world.plot(column='pop_est', legend=True, norm=matplotlib.colors.LogNorm(vmin=world.pop_est.min(), vmax=world.pop_est.max()), )
如果我有下面的图,我怎样才能把 colormap/legend 变成对数刻度?
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)
您可以简单地绘制值的对数而不是值本身。
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)
GeoPandas 绘图使用 matplotlib,因此您可以使用它提供的色图标准化。请注意,我还将最小值和最大值指定为我正在绘制的列的最小值和最大值。
world.plot(column='pop_est', legend=True, norm=matplotlib.colors.LogNorm(vmin=world.pop_est.min(), vmax=world.pop_est.max()), )