最好用的分组数据可视化工具--Seaborn调色盘

上一篇文章写了Seaborn基本风格设置,这一篇文章写一下Seaborn中的调色盘设置
首先引入所需模块

import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

我们主要使用color_palette()来对调色盘进行各种设置
默认六种颜色:deep,muted, pastel, bright, dark, colorblind
seaborn, color_palette(palette=None, n_colors = None, desat = None)

current_palette=sns.color_palette()
sns.palplot(current_palette)

在这里插入图片描述
颜色风格为‘vlag’,颜色色块个数为8

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

在这里插入图片描述
分组颜色设置为‘Paired’,色块为10

sns.palplot(sns.color_palette('Paired',10))

在这里插入图片描述
设置亮度,饱和度
有两种方法可以设置:
#(1)husl_palette([n_colors,h,s,l])
#(2)hls_palette([n_colors,h,l,s])

sns.palplot(sns.hls_palette(8,l=.5,s=.5))
#l---亮度
#s--饱和度

在这里插入图片描述
我们可以通过cubehelix_palette()函数
#按照线性增长计算,设置颜色

sns.palplot(sns.cubehelix_palette(8,gamma=2))
sns.palplot(sns.cubehelix_palette(8,start=.5,rot=-.75))
sns.palplot(sns.cubehelix_palette(8,start=2,rot=0,dark=0,light=.95,reverse=True))
#n_colors--颜色个数
#start--值区间在0-3,开始颜色
#rot-颜色旋转角度
#gamma-颜色伽马值,越大颜色越暗
#dark,light--值区间在0-1,颜色深浅
#reverse--布尔值,默认为False,由浅到深

在这里插入图片描述
通过dark_palette(color[,n_colors,reverse,…])/light_palette(color[,n_colors,reverse,…])来设置颜色深浅

sns.palplot(sns.light_palette('green'))#按照green做浅色调色盘
sns.palplot(sns.color_palette('Greens'))#cmap为Greens风格

sns.palplot(sns.dark_palette('red',reverse=True))#按照red做深色调色盘
#reverse---转置颜色

在这里插入图片描述
通过diverging_palette()创建分散颜色
#seaborn.diverging_palette(h_neg,h_pos,s=75,l=50,sep=10,n=6,
#center=‘light’,as_cmap=False)
#h_neg,h_pos–起始/终止颜色值,145为起始颜色值,280为终止颜色值
#s-值区间0-100,饱和度
#l-值区间0-100,亮度
#n-颜色个数
#center–中心颜色为深色还是浅色,默认为light

sns.palplot(sns.diverging_palette(145,280,s=85,l=25,n=7))

在这里插入图片描述

plt.figure(figsize=(8,6))
x=np.arange(25).reshape(5,5)
cmap=sns.diverging_palette(200,20,sep=20,as_cmap=True)#调色板,20020,步骤为20步
sns.heatmap(x,cmap=cmap)

在这里插入图片描述
设置调色板后,绘图创建图表,设置部分风格

sns.set_style('whitegrid')
#设置风格

with sns.color_palette('PuBuGn_d'):
    plt.subplot(211)
    sinplot()
    
sns.set_palette('husl')
plt.subplot(212)
sinplot()
#绘制系列颜色

在这里插入图片描述
调色盘设置大概就是这些啦
关注欢喜,一起进步呀~
微信公众号,这个公众号里面不止有Python的内容哦,还有C++,微信小程序,以及一些课程实验啊课设啊源码哦~
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值