创建不对称的色彩映射

问题描述 投票:2回答:1

我正在使用map colors的代码在folors choropleth地图中为here创建一个色彩映射表:

from branca.colormap import linear

colormap = linear.RdBu.scale(
    df.MyValue.min(),
    df.MyValue.max())

colormap

my colormap

正如您所看到的,min和max值与0相比是偏斜的,我希望它反映在colormap中,即只有值<0应该映射到红色,而所有正值都应该映射到蓝色。

有没有办法在色彩映射中具有这种不对称性?我没有在网上看到很多例子。

我这样做:

colormap = colormap.to_step(index=[-200, 0, 1200])

但它并不顺利:

enter image description here

python folium
1个回答
3
投票

如果需要非对称色标,可以设置索引(在文档中称为不规则)。例:

import branca.colormap as cm

colormap = cm.LinearColormap(colors=['red','blue'], index=[-200,0],vmin=-200,vmax=1200)
colormap

enter image description here

转换将由您的索引给出。例如,这是其他转换:

colormap = cm.LinearColormap(colors=['red','blue'], index=[0,200],vmin=-200,vmax=1200)
colormap

enter image description here

添加第三种颜色:

   colormap = cm.LinearColormap(colors=['red','lightblue','blue'], index=[-200,0,1200],vmin=-200,vmax=1200)
    colormap

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.