当前位置:网站首页>通过函数seaborn.cubehelix_palette生成顺序调色板
通过函数seaborn.cubehelix_palette生成顺序调色板
2022-06-13 06:53:00 【承危】
沉舟侧畔千帆过,病树前头万木春。 ——刘禹锡
import numpy as np
import seaborn as sns
引言
- 本文主要对seaborn库中的调色板函数
cubehelix_palette
进行简单说明 - 函数
cubehelix_palette
通过cubehelix系统来生成顺序调色板(sequential palette)、且共有九个参数可以调整 - 实际上、本文并未总结出显著的规律性方法来调用该函数、但记住一些常用的调色板所对应的参数、并善于对参数进行微调可能才是更为有用的指导
正文开始
- 查看默认调色板、jupyter中直接调用函数
sns.cubehelix_palette()
就可以显示 - 显然从明到暗、6种颜色
sns.palplot(sns.cubehelix_palette())
- 由于函数默认返回的是RGB元组列表(list of RGB tuples)、所以可以通过整数或者切片来选取调色板中的部分颜色
sns.palplot(sns.cubehelix_palette()[:: 2])
参数rot
控制在调色板的范围内围绕色调轮旋转- 通过从-0.5到0.6且步长为0.1的循环来查看所生成的颜色表、
参数n_colors
控制生成色块的数量
for rot in np.arange(start=-0.5, stop=0.6, step=0.1):
sns.palplot(sns.cubehelix_palette(n_colors=12, rot=rot))
参数start
控制螺旋线开始的色调- 可以进行一些对比、这是不设置开始色调时生成的颜色表
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=-.2))
- 同样循环改变参数start、且产生了和参数rot类似的效果
- 但并没有发现可循的规律…
for start in np.arange(start=0, stop=3, step=0.6):
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=-.2, start=start))
参数gamma
控制颜色的明暗、越小于1越亮、越大于1越暗
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=0.2, gamma=0.1))
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=0.2, gamma=0.5))
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=0.2))
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=0.2, gamma=1.5))
sns.palplot(sns.cubehelix_palette(n_colors=8, rot=0.2, gamma=2.5))
参数hue
控制颜色的饱和度- 官网所给出的范围是从0到1、但超出来也并没有什么问题
for hue in np.arange(start=-0.5, stop=2.0, step=0.5):
sns.palplot(sns.cubehelix_palette(rot=0.5, hue=hue))
参数dark
和参数light
分别控制调色板/颜色表中最暗和最亮颜色的强度- 使用的时候慢慢调整到合适的、所需要的颜色吧
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5, dark=0.05))
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5))
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5, dark=0.5))
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5, light=0.3))
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5, light=0.5))
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5))
- 参数light取0.85、或参数dark取0.15为默认值
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5)) == sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5, light=0.85))
True
sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5)) == sns.palplot(sns.cubehelix_palette(rot=-0.2, gamma=0.5, dark=0.15))
True
参数reverse
可以将调色板从明到暗改为从暗到明
sns.palplot(sns.cubehelix_palette(rot=-0.5, gamma=0.5))
sns.palplot(sns.cubehelix_palette(rot=-0.5, gamma=0.5, reverse=True))
参数as_cmap
可以将函数返回值从RGB元组列表
改为matplotlib的colors.Colormap数据类型
- 这样就可以通过顺序调色板函数
cubehelix_palette
来设置其他绘图函数中的参数cmap
cmap = sns.cubehelix_palette(rot=-0.2, as_cmap=True, light=1)
sns.heatmap(data=np.arange(25).reshape(5, 5), cmap=cmap)
边栏推荐
- How to quickly support the team leader to attract new fission users in the business marketing mode of group rebate?
- [Tencent Alibaba's most comprehensive collection of test questions] (four sides: three rounds of technology +1 round of HR)
- Introduction and use of dumping
- Tidb grafana reverse proxy
- YOLOv5解析 | 参数与性能指标
- ML:机器学习模型的稳定性分析简介、常见的解决方法之详细攻略
- Intelligent entertainment has developed steadily, and jinglianwen technology provides data collection and labeling services
- Application of DS18B20 temperature sensor based on FPGA
- 105. constructing binary trees from preorder and inorder traversal sequences
- Array operations in JS
猜你喜欢
随机推荐
Machine learning notes - supervised learning memo list
Why is the blind box e-commerce mode so popular?
百货中心供应链管理系统
上位机开发(固件下载软件之架构设计)
学习Mysql基础第一天
号称下一代监控系统 来看看它有多牛逼
基于SSM实现水果商城批发平台
怎么写出一份令人惊叹的设计文档?
上位机开发(固件下载软件之软件测试)
Vue3 route cache component status and set transition animation
Upper computer development (software test of firmware download software)
Upper computer development (detailed design of firmware download software)
Br tool backup recovery
Uploading and retrieving stored images in localstorage
MySQL系列之分库分表学习笔记
How to quickly support the team leader to attract new fission users in the business marketing mode of group rebate?
髋关节MR详细图谱(转载)
June 12, 2022: if there are n*n pieces in an n*n square chessboard, each grid can have exactly one piece. But now some pieces are gathered on a grid, such as 2030100300. The above two-dimensional arra
Outil de formatage du temps - mode. JS (affichage en temps réel du temps Web)
JS case Xiaomi second kill countdown New Year Countdown