你能颠倒布兰卡色彩图的顺序吗?
Can you reverse the order of a branca colormap?
我有一个 branca 颜色图,可以翻转它的顺序吗?
例如
这个:
为此:
代码:
import branca.colormap as cm
den_colormap = cm.linear.RdBu_11
cm.linear
是 LinearColormap
个实例的集合。
LinearColormap
具有颜色列表 colors
以及最小值 vmin
和最大值 vmax
作为属性,即用于将值线性映射到颜色。
LinearColormap
初始化程序将颜色列表以及最小值和最大值作为参数。
因此,您可以根据现有实例创建一个新的 LinearColormap
实例,方法是传递颠倒的颜色列表并使用相同的最小值和最大值。
def reversed_colormap(existing):
return cm.LinearColormap(
colors=list(reversed(existing.colors)),
vmin=existing.vmin, vmax=existing.vmax
)
示例:
RdBu_11_reverse = reversed_colormap(cm.linear.RdBu_11)
试试这个:
import branca.colormap as cm
den_colormap = cm.linear.RdBu_11.colors
print('Original : \n', den_colormap)
den_colormap.reverse()
print('reversed : \n', den_colormap)
out = cm.LinearColormap(colors=den_colormap)
print('out : \n', out.colors)
输出:
Original :
[(0.403921568627451, 0.0, 0.12156862745098039, 1.0), (0.6980392156862745, 0.09411764705882353, 0.16862745098039217, 1.0), (0.8392156862745098, 0.3764705882352941, 0.30196078431372547, 1.0), (0.9568627450980393, 0.6470588235294118, 0.5098039215686274, 1.0), (0.9921568627450981, 0.8588235294117647, 0.7803921568627451, 1.0), (0.9686274509803922, 0.9686274509803922, 0.9686274509803922, 1.0), (0.8196078431372549, 0.8980392156862745, 0.9411764705882353, 1.0), (0.5725490196078431, 0.7725490196078432, 0.8705882352941177, 1.0), (0.2627450980392157, 0.5764705882352941, 0.7647058823529411, 1.0), (0.12941176470588237, 0.4, 0.6745098039215687, 1.0), (0.0196078431372549, 0.18823529411764706, 0.3803921568627451, 1.0)]
reversed :
[(0.0196078431372549, 0.18823529411764706, 0.3803921568627451, 1.0), (0.12941176470588237, 0.4, 0.6745098039215687, 1.0), (0.2627450980392157, 0.5764705882352941, 0.7647058823529411, 1.0), (0.5725490196078431, 0.7725490196078432, 0.8705882352941177, 1.0), (0.8196078431372549, 0.8980392156862745, 0.9411764705882353, 1.0), (0.9686274509803922, 0.9686274509803922, 0.9686274509803922, 1.0), (0.9921568627450981, 0.8588235294117647, 0.7803921568627451, 1.0), (0.9568627450980393, 0.6470588235294118, 0.5098039215686274, 1.0), (0.8392156862745098, 0.3764705882352941, 0.30196078431372547, 1.0), (0.6980392156862745, 0.09411764705882353, 0.16862745098039217, 1.0), (0.403921568627451, 0.0, 0.12156862745098039, 1.0)]
out :
[(0.0196078431372549, 0.18823529411764706, 0.3803921568627451, 1.0), (0.12941176470588237, 0.4, 0.6745098039215687, 1.0), (0.2627450980392157, 0.5764705882352941, 0.7647058823529411, 1.0), (0.5725490196078431, 0.7725490196078432, 0.8705882352941177, 1.0), (0.8196078431372549, 0.8980392156862745, 0.9411764705882353, 1.0), (0.9686274509803922, 0.9686274509803922, 0.9686274509803922, 1.0), (0.9921568627450981, 0.8588235294117647, 0.7803921568627451, 1.0), (0.9568627450980393, 0.6470588235294118, 0.5098039215686274, 1.0), (0.8392156862745098, 0.3764705882352941, 0.30196078431372547, 1.0), (0.6980392156862745, 0.09411764705882353, 0.16862745098039217, 1.0), (0.403921568627451, 0.0, 0.12156862745098039, 1.0)]
我有一个 branca 颜色图,可以翻转它的顺序吗?
例如
这个:
为此:
代码:
import branca.colormap as cm
den_colormap = cm.linear.RdBu_11
cm.linear
是LinearColormap
个实例的集合。LinearColormap
具有颜色列表colors
以及最小值vmin
和最大值vmax
作为属性,即用于将值线性映射到颜色。LinearColormap
初始化程序将颜色列表以及最小值和最大值作为参数。
因此,您可以根据现有实例创建一个新的 LinearColormap
实例,方法是传递颠倒的颜色列表并使用相同的最小值和最大值。
def reversed_colormap(existing):
return cm.LinearColormap(
colors=list(reversed(existing.colors)),
vmin=existing.vmin, vmax=existing.vmax
)
示例:
RdBu_11_reverse = reversed_colormap(cm.linear.RdBu_11)
试试这个:
import branca.colormap as cm
den_colormap = cm.linear.RdBu_11.colors
print('Original : \n', den_colormap)
den_colormap.reverse()
print('reversed : \n', den_colormap)
out = cm.LinearColormap(colors=den_colormap)
print('out : \n', out.colors)
输出:
Original :
[(0.403921568627451, 0.0, 0.12156862745098039, 1.0), (0.6980392156862745, 0.09411764705882353, 0.16862745098039217, 1.0), (0.8392156862745098, 0.3764705882352941, 0.30196078431372547, 1.0), (0.9568627450980393, 0.6470588235294118, 0.5098039215686274, 1.0), (0.9921568627450981, 0.8588235294117647, 0.7803921568627451, 1.0), (0.9686274509803922, 0.9686274509803922, 0.9686274509803922, 1.0), (0.8196078431372549, 0.8980392156862745, 0.9411764705882353, 1.0), (0.5725490196078431, 0.7725490196078432, 0.8705882352941177, 1.0), (0.2627450980392157, 0.5764705882352941, 0.7647058823529411, 1.0), (0.12941176470588237, 0.4, 0.6745098039215687, 1.0), (0.0196078431372549, 0.18823529411764706, 0.3803921568627451, 1.0)]
reversed :
[(0.0196078431372549, 0.18823529411764706, 0.3803921568627451, 1.0), (0.12941176470588237, 0.4, 0.6745098039215687, 1.0), (0.2627450980392157, 0.5764705882352941, 0.7647058823529411, 1.0), (0.5725490196078431, 0.7725490196078432, 0.8705882352941177, 1.0), (0.8196078431372549, 0.8980392156862745, 0.9411764705882353, 1.0), (0.9686274509803922, 0.9686274509803922, 0.9686274509803922, 1.0), (0.9921568627450981, 0.8588235294117647, 0.7803921568627451, 1.0), (0.9568627450980393, 0.6470588235294118, 0.5098039215686274, 1.0), (0.8392156862745098, 0.3764705882352941, 0.30196078431372547, 1.0), (0.6980392156862745, 0.09411764705882353, 0.16862745098039217, 1.0), (0.403921568627451, 0.0, 0.12156862745098039, 1.0)]
out :
[(0.0196078431372549, 0.18823529411764706, 0.3803921568627451, 1.0), (0.12941176470588237, 0.4, 0.6745098039215687, 1.0), (0.2627450980392157, 0.5764705882352941, 0.7647058823529411, 1.0), (0.5725490196078431, 0.7725490196078432, 0.8705882352941177, 1.0), (0.8196078431372549, 0.8980392156862745, 0.9411764705882353, 1.0), (0.9686274509803922, 0.9686274509803922, 0.9686274509803922, 1.0), (0.9921568627450981, 0.8588235294117647, 0.7803921568627451, 1.0), (0.9568627450980393, 0.6470588235294118, 0.5098039215686274, 1.0), (0.8392156862745098, 0.3764705882352941, 0.30196078431372547, 1.0), (0.6980392156862745, 0.09411764705882353, 0.16862745098039217, 1.0), (0.403921568627451, 0.0, 0.12156862745098039, 1.0)]