Python可视化学习之seaborn调色盘

 更新时间:2022年02月24日 16:53:27   作者:qq_21478261  
seaborn是在matplotlib基础上封装的,所以matplotlib的调色盘seaborn都可以使用。本文系统介绍seaborn调色盘,相较于matplotlib,有诸多不同,需要的可以参考一下

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"))

到此这篇关于Python可视化学习之seaborn调色盘的文章就介绍到这了,更多相关Python seaborn调色盘内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • python机器人运动范围问题的解答

    python机器人运动范围问题的解答

    这篇文章主要为大家详细解答了python机器人的运动范围问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-04-04
  • PyCharm2019.3永久激活破解详细图文教程,亲测可用(不定期更新)

    PyCharm2019.3永久激活破解详细图文教程,亲测可用(不定期更新)

    这篇文章主要介绍了PyCharm2019.3最新激活码(注册码)破解永久版详细图文教程的相关资料,亲测可用,需要的朋友可以参考下
    2020-10-10
  • python版本的仿windows计划任务工具

    python版本的仿windows计划任务工具

    这篇文章主要介绍了python版本的仿windows计划任务工具,计划任务工具根据自己设定的具体时间,频率,命令等属性来规定所要执行的计划,当然功能不是很全大家可以补充
    2018-04-04
  • PyQt5结合matplotlib绘图的实现示例

    PyQt5结合matplotlib绘图的实现示例

    这篇文章主要介绍了PyQt5结合matplotlib绘图的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-09-09
  • Python anaconda安装库命令详解

    Python anaconda安装库命令详解

    这篇文章主要介绍了Python anaconda安装库命令详解,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-10-10
  • python中sort和sorted排序的实例方法

    python中sort和sorted排序的实例方法

    在本篇文章中小编给大家带来的是关于python中sort和sorted排序的实例方法以及相关知识点,有需要的朋友们可以学习下。
    2019-08-08
  • OpenCV 轮廓检测的实现方法

    OpenCV 轮廓检测的实现方法

    这篇文章主要介绍了OpenCV 轮廓检测的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-07-07
  • Python 遗传算法处理TSP问题详解

    Python 遗传算法处理TSP问题详解

    遗传算法(Genetic Algorithm, GA)是模拟达尔文生物进化论的自然选择和遗传学机理的生物进化过程的计算模型,是一种通过模拟自然进化过程搜索最优解的方法
    2022-11-11
  • python中的log日志多线程安全

    python中的log日志多线程安全

    这篇文章主要介绍了python中的log日志多线程安全,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-08-08
  • Python模仿POST提交HTTP数据及使用Cookie值的方法

    Python模仿POST提交HTTP数据及使用Cookie值的方法

    这篇文章主要介绍了Python模仿POST提交HTTP数据及使用Cookie值的方法,通过两种不同的实现方法较为详细的讲述了HTTP数据通信及cookie的具体用法,需要的朋友可以参考下
    2014-11-11

最新评论