一、調色盤
對圖表整體顔色、比例進行風格設定,包括顔色色闆等
調用系統風格進行資料可視化
1.color_palette()
預設6種顔色:deep,muted, pastel, bright, dark, colorblind
seaborn, color_palette(palette=None, n_colors = None, desat = None)
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
current_palette = sns.color_palette()
sns.palplot(current_palette)
#其它顔色風格
#風格内容:Accent,Blues,BrBG等等
sns.palplot(sns.color_palette('Accent',8))
#這裡顔色風格為Accent
#顔色色塊個數為8個
#風格顔色轉換(不是所有顔色都可以反轉):Blues/Blues_r
#分組顔色設定 -'Paried'
sns.palplot(sns.color_palette('Paired', 16))
以下調色盤分别為current_palette, Accent, Paired

2、設定亮度,飽和度
可用方法:
2.1 husl_palette([n_colors, h, s, l])
2.2 hsl_palette([n_colors, h, l, s])
sns.palplot(sns.hls_palette(8 , l = .8, s = .5))
#l = 亮度
#s = 飽和度
3. cubehelix_palette()
按照線性增長計算,設定顔色
sns.palplot(sns.cubehelix_palette(8, gamma = 2))
sns.palplot(sns.cubehelix_palette(8, start = .5, rot = -.75))
sns.palplot(sns.cubehelix_palette(8, start = 2, rot = 0, dark = 0, light = .95, reverse = True)
#n_colors---> 顔色個數
#start ---> 值區間在0-3,開始顔色
#rot ---> 顔色旋轉角度
#gamma ---> 顔色伽馬值,越大顔色越暗
#dark,light ---> 值區間0-1,顔色越深
#reverse ---> 布爾值,預設為False,由淺到深
4.dark_palette(color[, n_colors, reverse, ...]) / light_palette(color[, n_colors, reverse, ...])
顔色深淺
sns.palplot(sns.light_palette('green')) #按照green做淺色調色盤
#sns.palplot(sns.color_palette('Greens')) #cmap為Greens風格
sns.palplot(sns.dark_palette('red', reverse = False)) #按照blue做深色調色盤
#reverse ---> 轉置顔色
注意light_palette和dark_palette的差別
5.diverging_palette()
建立分散顔色
#seaborn.diverging_palette(h_neg,
h_pos, s=75, l=50, sep=10, n=6, center='light', as_cmap=False)
sns.palplot(sns.diverging_palette(145,280, s=85, l=25, n=7))
#h_neg, h_pos ---> 起始/終止顔色值
#s ---> 值區間0-100,飽和度
#l ---> 值區間0-100,亮度
#n ---> 顔色個數
#center ---> 中心顔色為淺色還是深色'light', 'dark', 預設為light
示例:
plt.figure(figsize = (8,6))
x = np.arange(25).reshape(5,5)
cmap = sns.diverging_palette(200,20,sep=20,as_cmap=True)
sns.heatmap(x, cmap=cmap)#熱力圖
用分散顔色制作熱力圖