RGB 颜色图 Matplotlib 的子集到 html

Subset of colormap Matplotlib in RGB to html

我有兴趣使用 Matplotlib 中的 cmap('hot') 作为散景调色板。

首先,我选择

给出的 Matplotlib 颜色图子集
from Matplotlib.pyplot as plt
colors_mpl = [i for i in plt.get_cmap('hot')(np.linspace(0.05, 0.95, 6))]

最初,给定一组 RGB 颜色,我可以使用内置函数 to_hex.

转换为 html
from matplotlib.colors import to_hex
colors_html = [to_hex(rgb/255) for rgb in colors_mpl]]

但是,我得到的输出不是预期的,因为颜色之间的差异很小:

['#000000', '#010000', '#010000', '#010100', '#010100', '#010101']

预期输出为

['#2a0000', '#a30000', '#ff1d00', '#ff9800', '#ffff1b', '#ffffd0']

关于如何将颜色图正确转换为 html 的任何想法?

不要除以 255colors_mplt 已经在比例 0-1:

colors_html = [to_hex(rgb) for rgb in colors_mpl]
# out
# ['#2a0000', '#a30000', '#ff1d00', '#ff9800', '#ffff1b', '#ffffd0']