Python可視化學(xué)習(xí)之seaborn調(diào)色盤
1、color_palette() 函數(shù)
該函數(shù)是seaborn選取顏色關(guān)鍵函數(shù)
color_palette() will accept the name of any seaborn palette or matplotlib colorma
語(yǔ)法:seaborn.color_palette(palette=None, n_colors=None, desat=None)
import seaborn as sns import matplotlib.pyplot as plt plt.figure(dpi=250) sns.palplot(sns.color_palette())#輸出默認(rèn)顏色
print(sns.color_palette())#返回默認(rèn)顏色元組組成的list
#palette,傳入colormap名稱 sns.palplot(sns.color_palette(palette='Accent'))#使用matplotlib中的colormap
#n_colors sns.palplot(sns.color_palette(n_colors=21))#返回顏色種類,超過(guò)了自動(dòng)循環(huán)
# desat sns.palplot(sns.color_palette(n_colors=21, desat=0.2))#設(shè)置顏色飽和度
#with plt.figure(dpi=100) with sns.color_palette(n_colors=21):#循環(huán)使用色盤 _ = plt.plot(np.c_[np.zeros(21), np.arange(21)].T)
#傳入hex 格式顏色號(hào)給sns.color_palette flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"] sns.palplot(sns.color_palette(flatui))
#顏色使用 plt.figure(dpi=100) plt.subplot(1,2,1) plt.bar([1,2,3],[1,2,3],color=sns.color_palette()[0])#取一種顏色 plt.subplot(1,2,2) plt.bar([1,2,3],[1,2,3],color=sns.color_palette()[0:3])#取三種顏色
2、 seaborn可用調(diào)色盤
分三大類:‘sequential’(漸變色), ‘diverging’(不可描述,看下圖), ‘qualitative’(各種顏色區(qū)分鮮明)
choose_colorbrewer_palette函數(shù)
該函數(shù)可以預(yù)覽各種顏色盤, 只能在jupyter notebook中使用。
下面詳細(xì)介紹上面三類顏色。
Qualitative color palettes
to distinguish discrete chunks of data that do not have an inherent ordering,分如下幾類:
1、deep, muted, pastel, bright, dark, colorblind
2、hls
3、husl
4、palettable 5、xkcd
6、傳入顏色list
#deep, muted, pastel, bright, dark, colorblind for i in list('deep, muted, pastel, bright, dark, colorblind'.split(', ')): print(i,end='\t') sns.palplot(sns.color_palette(palette=i))
從上到下依次為:deep, muted, pastel, bright, dark, colorblind
# hls sns.palplot(sns.color_palette(palette='hls')) sns.palplot(sns.hls_palette(8, l=.3, s=.8))
#husl sns.palplot(sns.color_palette(palette='husl')) sns.palplot(sns.color_palette("husl", 8))
import palettable#python palettable庫(kù) sns.palplot(sns.color_palette(palette=palettable.colorbrewer.qualitative.Dark2_7.mpl_colors))#使用palettable中的colormap sns.palplot(sns.color_palette(palette=palettable.scientific.sequential.Nuuk_7.mpl_colors))
#xkcd 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)
xkcd,詳細(xì)可參考 :Python可視化學(xué)習(xí)之matplotlib內(nèi)置單顏色
#傳入顏色list給ns.xkcd_palette() colors = ["windows blue", "amber", "greyish", "faded green", "dusty purple"] sns.palplot(sns.xkcd_palette(colors))
Sequential color palettes
is appropriate when data range from relatively low or uninteresting values to relatively high or interesting values
1、"Blues"這類
2、'cubehelix',seaborn.cubehelix_palette(n_colors=6, start=0, rot=0.4, gamma=1.0, hue=0.8, light=0.85, dark=0.15, reverse=False, as_cmap=False)
3、傳統(tǒng)色的漸變色,light_palette()、dark_palette()
#"Blues"這類漸變色 sns.palplot(sns.color_palette("Blues")) sns.palplot(sns.color_palette("Blues_d"))#_d表示顯示該顏色的深色系(“dark” palettes by appending “_d”) sns.palplot(sns.color_palette("Blues_r"))
# cubehelix sns.palplot(sns.color_palette("cubehelix", 8)) sns.palplot(sns.color_palette("ch:2.5,-.2,dark=.3"))#使用cubehelix接口制作顏色 sns.palplot(sns.cubehelix_palette(8, start=2, rot=0, dark=0, light=.95, reverse=True))
#light_palette sns.palplot(sns.light_palette("seagreen", reverse=True)) sns.palplot(sns.light_palette((260, 75, 60), input="husl"))
Diverging color palettes
for data where both large low and high values are interesting.
1、diverging_palette()
sns.palplot(sns.color_palette("coolwarm", 7))
sns.palplot(sns.diverging_palette(240, 10, n=9)) sns.palplot(sns.diverging_palette(150, 275, s=80, l=55, n=9)) sns.palplot(sns.diverging_palette(250, 15, s=75, l=40, n=9, center="dark"))
到此這篇關(guān)于Python可視化學(xué)習(xí)之seaborn調(diào)色盤的文章就介紹到這了,更多相關(guān)Python seaborn調(diào)色盤內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python機(jī)器人運(yùn)動(dòng)范圍問(wèn)題的解答
這篇文章主要為大家詳細(xì)解答了python機(jī)器人的運(yùn)動(dòng)范圍問(wèn)題,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04PyCharm2019.3永久激活破解詳細(xì)圖文教程,親測(cè)可用(不定期更新)
這篇文章主要介紹了PyCharm2019.3最新激活碼(注冊(cè)碼)破解永久版詳細(xì)圖文教程的相關(guān)資料,親測(cè)可用,需要的朋友可以參考下2020-10-10python版本的仿windows計(jì)劃任務(wù)工具
這篇文章主要介紹了python版本的仿windows計(jì)劃任務(wù)工具,計(jì)劃任務(wù)工具根據(jù)自己設(shè)定的具體時(shí)間,頻率,命令等屬性來(lái)規(guī)定所要執(zhí)行的計(jì)劃,當(dāng)然功能不是很全大家可以補(bǔ)充2018-04-04PyQt5結(jié)合matplotlib繪圖的實(shí)現(xiàn)示例
這篇文章主要介紹了PyQt5結(jié)合matplotlib繪圖的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09python中sort和sorted排序的實(shí)例方法
在本篇文章中小編給大家?guī)?lái)的是關(guān)于python中sort和sorted排序的實(shí)例方法以及相關(guān)知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。2019-08-08OpenCV 輪廓檢測(cè)的實(shí)現(xiàn)方法
這篇文章主要介紹了OpenCV 輪廓檢測(cè)的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07Python模仿POST提交HTTP數(shù)據(jù)及使用Cookie值的方法
這篇文章主要介紹了Python模仿POST提交HTTP數(shù)據(jù)及使用Cookie值的方法,通過(guò)兩種不同的實(shí)現(xiàn)方法較為詳細(xì)的講述了HTTP數(shù)據(jù)通信及cookie的具體用法,需要的朋友可以參考下2014-11-11