網站首頁 編程語言 正文
1、color_palette() 函數
該函數是seaborn選取顏色關鍵函數
color_palette() will accept the name of any seaborn palette or matplotlib colorma
語法: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())#輸出默認顏色
print(sns.color_palette())#返回默認顏色元組組成的list
#palette,傳入colormap名稱 sns.palplot(sns.color_palette(palette='Accent'))#使用matplotlib中的colormap
#n_colors sns.palplot(sns.color_palette(n_colors=21))#返回顏色種類,超過了自動循環
# desat sns.palplot(sns.color_palette(n_colors=21, desat=0.2))#設置顏色飽和度
#with plt.figure(dpi=100) with sns.color_palette(n_colors=21):#循環使用色盤 _ = plt.plot(np.c_[np.zeros(21), np.arange(21)].T)
#傳入hex 格式顏色號給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可用調色盤
分三大類:‘sequential’(漸變色), ‘diverging’(不可描述,看下圖), ‘qualitative’(各種顏色區分鮮明)
choose_colorbrewer_palette函數
該函數可以預覽各種顏色盤, 只能在jupyter notebook中使用。
下面詳細介紹上面三類顏色。
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庫 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,詳細可參考 :Python可視化學習之matplotlib內置單顏色
#傳入顏色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、傳統色的漸變色,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"))
原文鏈接:https://blog.csdn.net/qq_21478261/article/details/107945630
相關推薦
- 2022-09-13 iOS自定義相機功能_IOS
- 2022-10-17 Net?core中使用System.Drawing對上傳的圖片流進行壓縮(示例代碼)_實用技巧
- 2022-10-31 Kotlin協程開發之Flow的融合與Channel容量及溢出策略介紹_Android
- 2023-07-25 使用POI導出Excel
- 2022-07-14 Android實現多點觸控功能_Android
- 2022-10-23 C#泛型集合類型實現添加和遍歷_C#教程
- 2023-02-06 詳解C#如何加密解密RAR文件_C#教程
- 2022-08-23 python?matplotlib畫圖時坐標軸重疊顯示不全和圖片保存時不完整的問題解決_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支