【发布时间】:2019-04-14 20:44:43
【问题描述】:
我有一个GeoDataFrame,其中有一个“差异”列,用于存储两个数字之间的差值。有时,如果没有差异,这些数字是正数、负数或零。我需要制作一个 choropleth 地图,它有一些不同的颜色图,其中 0(或一些中间缓冲区)作为中点和非对称颜色条,例如 [-0.02, -0.01, 0., 0.01, 0.02, 0.03]。我试过了
class MidPointNormalize(mp.colors.Normalize):
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
self.midpoint = midpoint
mp.colors.Normalize.__init__(self, vmin, vmax, clip)
def __call__(self, value, clip=None):
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
return np.ma.masked_array(np.interp(value, x, y), np.isnan(value))
norm = MidPointNormalize(midpoint=0,vmin=diff_merge_co["diff"].min(),
vmax=diff_merge_co["diff"].max())
diff_merge_co.plot(ax=ax, column="diff", cmap="coolwarm", norm=norm,
legend=True)
并将norm 设置为一些精心挑选的值:
bounds = np.array([-0.02, -0.01, 0., 0.01, 0.02, 0.03])
norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256)
但是这有很多技术问题(包括颜色条没有向上持续,以及手工挑选值的明显丑陋)。
所以我的问题是:您将如何使用geopandas.GeoDataFrame.plot() 绘制具有不同比例的地图,您将使用哪种mapclassify 方法?
【问题讨论】:
-
另见评论the github issue
标签: python matplotlib gis geopandas