是的,但这可能取决于您对哪种类型的色彩空间感兴趣。如果您想获得一堆具有相似感知亮度的颜色,我是HUSL 色彩空间。
Seaborn 为 color picking 提供了一个不错的 API。要获得一堆具有不同亮度的颜色,请尝试dark_palette 或light_palette。要获得起始颜色,您可以从 husl_palette 生成的颜色开始,这样所有凝视颜色都具有相同的感知亮度。
把这些放在一起:
x_colors = 10; y_colors=10
husl_pal = sns.husl_palette(y_colors, l=0.8)
fig, axs = plt.subplots(10,1)
for i,color in enumerate(husl_pal):
# cut off first color because it is extra dark
my_palplot(sns.dark_palette(color, x_colors+1)[1:], ax=axs[i])
我借用了一个自定义 sns.palplot() 函数,该函数允许从 this question 传递轴对象
def my_palplot(pal, size=1, ax=None):
"""Plot the values in a color palette as a horizontal array.
Parameters
----------
pal : sequence of matplotlib colors
colors, i.e. as returned by seaborn.color_palette()
size :
scaling factor for size of plot
ax :
an existing axes to use
"""
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
n = len(pal)
if ax is None:
f, ax = plt.subplots(1, 1, figsize=(n * size, size))
ax.imshow(np.arange(n).reshape(1, n),
cmap=mpl.colors.ListedColormap(list(pal)),
interpolation="nearest", aspect="auto")
ax.set_xticks(np.arange(n) - .5)
ax.set_yticks([-.5, .5])
# Ensure nice border between colors
ax.set_xticklabels(["" for _ in range(n)])
# The proper way to set no ticks
ax.yaxis.set_major_locator(ticker.NullLocator())