从下面
branca
颜色图
import branca
color_map = branca.colormap.linear.PuRd_09.scale(0, 250)
colormap = color_map.to_step(index=[0, 10, 20, 50, 70, 90, 120, 200])
如何从上面的
Branca
颜色图中提取所有步骤(索引)的十六进制颜色?
上使用
colormap.colors
:
from matplotlib.colors import to_hex
out = [to_hex(c) for c in colormap.colors]
# or
out = list(map(to_hex, colormap.colors))
输出:
['#f7f4f9', '#f0ebf4', '#e3d9eb', '#d0aad2', '#d084bf', '#e44199', '#67001f']
基于 https://github.com/python-visualization/branca/blob/main/branca/colormap.py:
中的函数["#%02x%02x%02x" % tuple(int(u * 255.9999) for u in i[:3]) for i in colormap.colors]
对于每种颜色:
输出:
['#f7f4f9', '#f0ecf5', '#e4d9eb', '#d0aad3', '#d184c0', '#e44199', '#67001f']