我经常忘记我想要使用的 colored颜色 的名称,并不断回到这个问题=)
前面的答案都很棒,但我发现要从张贴的图片中获得可用 colored颜色 的概述有点困难.我更喜欢用相似的 colored颜色 分组,所以我稍微调整了上面 comments 中提到的matplotlib answer个 colored颜色 列表,以获得按列排序的 colored颜色 列表.这个顺序与我用眼睛排序的方式不一样,但我认为它提供了一个很好的概述.
I updated the image and code to reflect that 'rebeccapurple' has been added and the three sage colors have been moved under the 'xkcd:' prefix since I posted this answer originally.个
与matplotlib示例相比,我确实没有太大改变,但下面是完整性代码.
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
# Sort colors by hue, saturation, value and name.
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
for name, color in colors.items())
sorted_names = [name for hsv, name in by_hsv]
n = len(sorted_names)
ncols = 4
nrows = n // ncols
fig, ax = plt.subplots(figsize=(12, 10))
# Get height and width
X, Y = fig.get_dpi() * fig.get_size_inches()
h = Y / (nrows + 1)
w = X / ncols
for i, name in enumerate(sorted_names):
row = i % nrows
col = i // nrows
y = Y - (row * h) - h
xi_line = w * (col + 0.05)
xf_line = w * (col + 0.25)
xi_text = w * (col + 0.3)
ax.text(xi_text, y, name, fontsize=(h * 0.8),
horizontalalignment='left',
verticalalignment='center')
ax.hlines(y + h * 0.1, xi_line, xf_line,
color=colors[name], linewidth=(h * 0.8))
ax.set_xlim(0, X)
ax.set_ylim(0, Y)
ax.set_axis_off()
fig.subplots_adjust(left=0, right=1,
top=1, bottom=0,
hspace=0, wspace=0)
plt.show()
其他命名 colored颜色
Updated 2017-10-25. I merged my previous updates into this section.
xkcd
如果要在使用matplotlib打印时使用其他命名 colored颜色 ,可以通过"xkcd:"前缀使用xkcd crowdsourced color names:
plt.plot([1,2], lw=4, c='xkcd:baby poop green')
现在您可以访问过多的命名 colored颜色 了!
人构成的画面或场景
matplotlib中的默认表格 colored颜色 通过"tab:"前缀提供:
plt.plot([1,2], lw=4, c='tab:green')
有十种不同的 colored颜色 :
HTML
您还可以按 colored颜色 的HTML hex code绘制 colored颜色 :
plt.plot([1,2], lw=4, c='#8f9805')
这更类似于指定和RGB元组,而不是指定 colored颜色 (除了十六进制代码作为字符串传递的事实),我将不包括1600万种 colored颜色 的图像,您可以从中 Select ...
有关更多详细信息,请参阅the matplotlib colors documentation和指定可用 colored颜色 的源文件_color_data.py
.