Seaborn--調色板(二)

調色板

顏色很重要
color_palette()能傳入任何Matplotlib所支持的顏色
color_palette()不寫參數則默認顏色
set_palette()設置所有圖的顏色
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
sns.set(rc={"figure.figsize": (6, 6)})

分類色板

current_palette = sns.color_palette()
sns.palplot(current_palette)#調色盤爲current_palette

在這裏插入圖片描述6個默認的顏色循環主題: deep, muted, pastel, bright, dark, colorblind

圓形畫板

當你有六個以上的分類要區分時,最簡單的方法就是在一個圓形的顏色空間中畫出均勻間隔的顏色(這樣的色調會保持亮度和飽和度不變)。這是大多數的當他們需要使用比當前默認顏色循環中設置的顏色更多時的默認方案。

最常用的方法是使用hls的顏色空間,這是RGB值的一個簡單轉換。

sns.palplot(sns.color_palette("hls", 8)) #顏色色塊個數爲8個

在這裏插入圖片描述

data = np.random.normal(size=(20, 8)) + np.arange(8) / 2
sns.boxplot(data=data,palette=sns.color_palette("hls", 8))

在這裏插入圖片描述
hls_palette()函數來控制顏色的亮度和飽和

l-亮度 lightness
s-飽和 saturation
sns.palplot(sns.hls_palette(8, l=.7, s=.9))

在這裏插入圖片描述

sns.palplot(sns.color_palette("Paired",8)) #分組顏色設置 -'Paried'

在這裏插入圖片描述
使用xkcd顏色來命名顏色
xkcd包含了一套衆包努力的針對隨機RGB色的命名。產生了954個可以隨時通過xdcd_rgb字典中調用的命名顏色。

plt.plot([0, 1], [0, 1], sns.xkcd_rgb["pale red"], lw=3)
plt.plot([0, 1], [0, 2], sns.xkcd_rgb["medium green"], lw=3)
plt.plot([0, 1], [0, 3], sns.xkcd_rgb["denim blue"], lw=3)

在這裏插入圖片描述

colors = ["windows blue", "amber", "greyish", "faded green", "dusty purple"]
sns.palplot(sns.xkcd_palette(colors))

在這裏插入圖片描述
連續色板
色彩隨數據變換,比如數據越來越重要則顏色越來越深

sns.palplot(sns.color_palette("Blues"))

在這裏插入圖片描述如果想要翻轉漸變,可以在面板名稱中添加一個_r後綴

sns.palplot(sns.color_palette("BuGn_r"))

在這裏插入圖片描述
cubehelix_palette()調色板
色調線性變換

sns.palplot(sns.color_palette("cubehelix", 8))

在這裏插入圖片描述

sns.palplot(sns.cubehelix_palette(8, start=.5, rot=-.75))

在這裏插入圖片描述

sns.palplot(sns.cubehelix_palette(8, start=.75, rot=-.150))

在這裏插入圖片描述
light_palette() 和dark_palette()調用定製連續調色板

sns.palplot(sns.light_palette("green")) #按照green做淺色調色盤

在這裏插入圖片描述

sns.palplot(sns.dark_palette("purple")) #按照purple做深色調色盤

在這裏插入圖片描述

sns.palplot(sns.light_palette("navy", reverse=True))
#reverse ---> 轉置顏色

在這裏插入圖片描述

x, y = np.random.multivariate_normal([0, 0], [[1, -.5], [-.5, 1]], size=300).T
pal = sns.dark_palette("green", as_cmap=True)
sns.kdeplot(x, y, cmap=pal);

在這裏插入圖片描述

sns.palplot(sns.light_palette((210, 90, 60), input="husl"))
#從 HUSL 空間種子生成選項板  還是用默認參數比較好,如果對顏色空間很熟,也可以指定好顏色空間。

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章