Python可视化_matplotlib08-palettabl
本文细介绍python palettable颜色库种colormap使用。
首发于本人公众号:pythonic生物人
本文将学到什么?
1、 palettable中colormap名称
16大类
1587类
2、 palettable中colormap可视化
3、palettable中colormap属性
4、palettable中colormap使用
更好的阅读体验请戳:
python Palettable库中颜色条Colormap使用
1、 palettable中colormap名称
palettable中颜色条分为16大类,每类中还有不同小类,共计1587种colormap。
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.wesanderson
1587类
共计1587个colormap,其实每种色条还有对应的反向色条(ArmyRose_2的反向色条ArmyRose_2_r),感兴趣可以公众号后台索取。以下列出部分。
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
palettable.cartocolors.diverging.Fall_2
palettable.cartocolors.diverging.Fall_3
palettable.cartocolors.diverging.Fall_4
palettable.cartocolors.diverging.Fall_5
palettable.cartocolors.diverging.Fall_6
palettable.cartocolors.diverging.Fall_7
palettable.cartocolors.diverging.Geyser_2
palettable.cartocolors.diverging.Geyser_3
palettable.cartocolors.diverging.Geyser_4
palettable.cartocolors.diverging.Geyser_5
palettable.cartocolors.diverging.Geyser_6
palettable.cartocolors.diverging.Geyser_7
palettable.cartocolors.diverging.TealRose_2
palettable.cartocolors.diverging.TealRose_3
palettable.cartocolors.diverging.TealRose_4
palettable.cartocolors.diverging.TealRose_5
2、 palettable中colormap可视化
将所有的色条绘制了5张图,便于查阅,感兴趣可以公众号索取。 image3、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')#保存图片
imageDark2
<class 'palettable.colorbrewer.colorbrewer.BrewerMap'>
7
[[27, 158, 119], [217, 95, 2], [117, 112, 179], [231, 41, 138], [102, 166, 30], [230, 171, 2], [166, 118, 29]]
<class 'list'>
['#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)]
<matplotlib.colors.LinearSegmentedColormap object at 0x000000000CAEC240>
4、palettable中colormap使用
以palettable.colorbrewer.qualitative.Dark2_7为例。Dark2_7的色条是什么样的? imageimport 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)
image
5 、参考资料
同系列好文
python matplotlib-颜色(一)
python matplotlib-颜色(二)
python matplotlib-颜色colormap(三)
欢迎关注公众号:pythonic生物人