调色盘
2021-8-16
| 2023-8-6
0  |  阅读时长 0 分钟
type
status
date
slug
summary
tags
category
icon
password
Property

 
 
seaborn可以非常迅速的做出优美的图形,其中就应该得力于他的调色盘机制。seaborn根据应用场景提供了三种不同类型的调色盘:定性的连续的发散的

定性调色盘

定性调色盘,一般在数据不连续,比较离散,想体现分类的情况下使用。
seaborn中,使用sns.color_palette来创建调色盘

默认调色盘

seaborn中,默认情况下就设置了一些颜色供绘图使用。使用sns.color_palette即可获取。并且可以通过sns.palplot来绘制调色盘:
 
 
notion image
 
 
 
 
notion image
 
 
notion image
notion image
默认的调色盘有10中颜色。这些颜色都有6中风格。分别是:deepmutedpastel, brightdarkcolorblind。这几种风格的颜色不变,主要调整的是亮度和饱和度。
notion image

hls圆形颜色系统

hls圆形颜色系统是颜色按照顺序,经过偏移,无缝形成一个圆形。在使用这个调色盘的时候,可以指定需要使用多少种颜色。
notion image
 
也可以使用另外一个函数sns.hls_palette(n_colors=6, h=0.01, l=0.6, s=0.65)来实现。这个函数可以传递更多的参数。比如我们可以通过更改hue来更改开始的颜色,通过更改l来调整亮度,通过更改s来调整饱和度。
notion image
 
另外也可以通过sns.husl_palette来实现色系的调整,这个方法比sns.hls_palette亮度和饱和度更加的均匀:
notion image
 

分类颜色

分类颜色是seaborn已经提前给你定义了一些颜色,使用这些颜色在做分类分组的时候可以按照自己的需求选择:
notion image
关于分类的颜色选择,可以通过sns.choose_colorbrewer_palette("qualitative")来查看。这个方法只能用在jupyter notebook中。可以选择不同的样式,然后还可以调节饱和度等:
notion image
 

用xkcd颜色

xkcd是一个漫画名称或者是工作室。xkcd开展了一项众包活动,为随机的RGB颜色命名。这产生了一组954种命名颜色。可以从sns.xkcd_palette里面提取颜色。提取到后,如果想要用在palette参数中,那么还需要放到sns.xkcd_palette中。所有的xkcd颜色的名称可以参考官网:https://xkcd.com/color/rgb/
 
 
 
 
notion image
 
notion image
notion image
 
 

连续的颜色盘

有时候我们绘图的时候,想要使用一个同种色系,但是不同深浅,这时候就可以使用连续的颜色盘:
 
 
notion image
默认颜色是从浅入深,如果想要从深变浅,那么可以在色系后加一个_r
 
 
notion image
 
也可以通过sns.choose_colorbrewer_palette("sequential")查看有哪些色系可供选择。效果图如下:
notion image
 

离散的色盘

离散的色盘,是两边的颜色逐渐加深,中间的颜色最淡。或者是中间的颜色最深,两边的颜色最淡。一般离散的色盘可以用于比如温度,零度以上可以用红色表示,零度以下用蓝色表示。越红的地方,表示温度越高,越蓝的地方,表示温度越低:
notion image
也可以通过sns.choose_colorbrewer_palette("diverging")查看离散的色盘有哪些可以选择。还可以通过sns.diverging_palette(h_neg, h_pos, s=75, l=50, sep=10, n=6, center='light',as_cmap=False)来自定义离散色盘。
 
官方文档:
  • Seaborn
  • 样式风格设置Pyecharts
    目录