详细介绍Palettable库中颜色条Colormap使用。

目录1、palettable中colormap名称

16大类

1587类

2、palettable中colormap可视化

3、palettable中colormap属性

4、palettable中colormap使用

5、参考资料

palettable是一个纯python写的Colormap颜色库,他的前生是brewer2mp,包含了matplotlib中部分色条,同时汇集了其它大量优美的色条;

palettable中颜色条是一种ColormapListedColormap类颜色条(每类Colormap中的每种颜色色号都可以取出来单独使用);

警告:部分篇幅比较大,请选择感兴趣的章节食用,看张颜色效果图:

1、 palettable中colormap名称

palettable中颜色条分为16大类,每大类中还有不同小类,共计1587小类colormap(和Matplotlib内置的颜色条一样,每种具有自己的反向颜色条,加“_r”即可使用)。16大类palettable.cartocolors.diverging

palettable.cartocolors.qualitative

palettable.cartocolors.sequential

palettable.cmocean.diverging

palettable.cmocean.sequential

palettable.colorbrewer.diverging

palettable.colorbrewer.qualitative

palettable.colorbrewer.sequential

palettable.lightbartlein.diverging

palettable.lightbartlein.sequential

palettable.scientific.diverging

palettable.scientific.sequential

palettable.matplotlib

palettable.mycarta

palettable.tableau

palettable.wesanderson1587类

其实每种色条还有对应的反向色条(ArmyRose_2的反向色条ArmyRose_2_r),所以共计有3000+种;palettable.cartocolors.diverging.ArmyRose_2

palettable.cartocolors.diverging.ArmyRose_3

palettable.cartocolors.diverging.ArmyRose_4

palettable.cartocolors.diverging.ArmyRose_5

palettable.cartocolors.diverging.ArmyRose_6

palettable.cartocolors.diverging.ArmyRose_7

palettable.cartocolors.diverging.Earth_2

palettable.cartocolors.diverging.Earth_3

palettable.cartocolors.diverging.Earth_4

palettable.cartocolors.diverging.Earth_5

palettable.cartocolors.diverging.Earth_6

palettable.cartocolors.diverging.Earth_7

。。。。。。。

2、 palettable中colormap可视化

将1587种颜色条绘制为5张色卡图,便于查阅,感兴趣小伙伴公众号后台索取,部分如下:

​3、palettable中colormap属性

以palettable.colorbrewer.qualitative.Dark2_7为例

import palettes

from palettable.colorbrewer.qualitative import Dark2_7_r,Dark2_7

print(Dark2_7.name)#The name of the palette

print(type(Dark2_7))#'diverging', 'qualitative' and so on

print(Dark2_7.number)#number of defined colors

print(Dark2_7.colors)# a list of RGB tuples in the range 0-255.

print(type(Dark2_7.colors))

print(Dark2_7.hex_colors)#a list of hex strings (e.g. '#A912F4')

print(Dark2_7.mpl_colors)#RGB tuples in the range 0-1 as used by matplotlib

print(Dark2_7.mpl_colormap)#

Dark2_7.show_discrete_image()#Dark2_7各种颜色条图片

Dark2_7_r.show_discrete_image()#Dark2_7_r各种颜色离散型图片

Dark2_7.show_continuous_image()#Dark2_7各种颜色连续型型图片

Dark2_7.save_discrete_image('Dark2_7.jpg')#保存图片

Dark2_7.save_continuous_image('Dark2_7c.jpg')#保存图片Dark2

7

[[27, 158, 119], [217, 95, 2], [117, 112, 179], [231, 41, 138], [102, 166, 30], [230, 171, 2], [166, 118, 29]]

['#1B9E77', '#D95F02', '#7570B3', '#E7298A', '#66A61E', '#E6AB02', '#A6761D']

[(0.10588235294117647, 0.6196078431372549, 0.4666666666666667), (0.8509803921568627, 0.37254901960784315, 0.00784313725490196), (0.4588235294117647, 0.4392156862745098, 0.7019607843137254), (0.9058823529411765, 0.1607843137254902, 0.5411764705882353), (0.4, 0.6509803921568628, 0.11764705882352941), (0.9019607843137255, 0.6705882352941176, 0.00784313725490196), (0.6509803921568628, 0.4627450980392157, 0.11372549019607843)]

4、palettable中colormap使用

以palettable.colorbrewer.qualitative.Dark2_7为例。

Dark2_7的色条是什么样的?

import palettable

import matplotlib.pyplot as plt

plt.figure(dpi=150)

#取palettable包中颜色

#取一种颜色

plt.subplot(1,2,1)

plt.bar(range(5),range(1,6),color=palettable.colorbrewer.qualitative.Dark2_7.mpl_colors[3])

#取多种颜色

plt.subplot(1,2,2)

plt.bar(range(5),range(1,6),color=palettable.colorbrewer.qualitative.Dark2_7.mpl_colors)

5 、参考资料