当前位置:网站首页>seaborn绘图风格的设置
seaborn绘图风格的设置
2022-06-21 12:52:00 【51CTO】
一个好看的图表, 图表元素整体样式的协调共存会让人感觉赏心悦目,包括颜色设置,文字大小,边框粗细等各种样式。在seaborn中,可以通过不同的函数来修改图表的样式
1. context
主要是影响绘图元素的样式,比如文字和点的大小,线条宽度等,但是不会改变整体的绘图风格。通过plotting_context函数,可以看到context所影响的具体元素
>>> sns.plotting_context()
{'font.size': 24.0, 'axes.labelsize': 24.0, 'axes.titlesize': 24.0, 'xtick.labelsize': 22.0, 'ytick.labelsize': 22.0, 'legend.fontsize': 22.0, 'axes.linewidth': 2.5, 'grid.linewidth': 2.0, 'lines.linewidth': 3.0, 'lines.markersize': 12.0, 'patch.linewidth': 2.0, 'xtick.major.width': 2.5, 'ytick.major.width': 2.5, 'xtick.minor.width': 2.0, 'ytick.minor.width': 2.0, 'xtick.major.size': 12.0, 'ytick.major.size': 12.0, 'xtick.minor.size': 8.0, 'ytick.minor.size': 8.0, 'legend.title_fontsize': 24.0}
- 1.
- 2.
可以看到,主要是fontsize, linewidth, markersize这3种属性。在seaborn中,内置了以下4种context
1. notebook
2. paper
3. talk
4. poster
通过set_context函数可以设置对应的context, 用法如下
不设置context的情况下,图表样式如下

notebook对应的图表样式如下

paper对应的图表样式如下

talk对应的图表样式如下

poster对应的图表样式如下

2. style
这里的style和matplotlib中的style相同,涵盖了更多图形元素的样式。seaborn中内置的style有以下几种
1. darkgrid
2. whitegrid
3. dark
4. white
5. ticks
通过axes_style函数可以查看style对应的元素属性,用法如下
>>> sns. axes_style("white")
{'figure.facecolor': 'white', 'axes.labelcolor': '.15', 'xtick.direction': 'out', 'ytick.direction': 'out', 'xtick.color': '.15', 'ytick.color': '.15', 'axes.axisbelow': True, 'grid.linestyle': '-', 'text.color': '.15', 'font.family': ['sans-serif'], 'font.sans-serif': ['Arial', 'DejaVu Sans', 'Liberation Sans', 'Bitstream Vera Sans', 'sans-serif'], 'lines.solid_capstyle': 'round', 'patch.edgecolor': 'w', 'patch.force_edgecolor': True, 'image.cmap': 'rocket', 'xtick.top': False, 'ytick.right': False, 'axes.grid': False, 'axes.facecolor': 'white', 'axes.edgecolor': '.15', 'grid.color': '.8', 'axes.spines.left': True, 'axes.spines.bottom': True, 'axes.spines.right': True, 'axes.spines.top': True, 'xtick.bottom': False, 'ytick.left': False}
- 1.
- 2.
也支持临时设置对应的style值,用法如下
darkgrid对应的图表样式如下

whitegrid对应的图表样式如下

white对应的图表样式如下

dark对应的图表样式如下

ticks对应的图表样式如下

如果你需要修改style属性中的部分值,可以通过set_style函数来实现,用法如下
3. theme
theme用于一次性设置context, style, palette等属性,具体的,有以下两种函数
set是set_theme的别名,通过context, style可以快速的确定绘图风格,当然绘图风格中还有非常重要的一个组成部分,颜色梯度palette, 这一块的内容很多,在后面的文章中再详细介绍。
·end·

一个只分享干货的
生信公众号
边栏推荐
- postgreSQL中的MVCC
- vmware12虚拟机打开报错“\\.\Global\vmx86”: 系统找不到指定的文件。
- scrapy_redis分布式爬虫
- uva11991
- 漫谈公网网络延迟
- Educoder web exercises -- text level semantic elements
- Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway
- centos7 部署mysql 环境
- CVPR2022 | 上科大x小红书首次提出动作序列验证任务,可应用于体育赛事打分等多场景
- 深度学习实战(十):使用 PyTorch 进行 3D 医学图像分割
猜你喜欢

Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway

居家办公初体验之新得分享| 社区征文

Educoder Web练习题---交互元素

深度学习实战(十):使用 PyTorch 进行 3D 医学图像分割

Educoder table label - basic table structure

Centos7 deploying MySQL environment

SSH password free login

AGCO AI frontier promotion (6.21)

用时间戳优化 TCP 实践

Kubernetes' fast practice and core principle analysis
随机推荐
Analysis on the wallet system architecture of Baidu trading platform
redis中的数据类型
Efficient remote office manual | community essay solicitation
uva11991
『忘了再学』Shell流程控制 — 35、多分支case条件语句
Educoder web exercises - form structure
基于STM32电压检测和电流检测
uva11300
处理接口幂等性的两种常见方案
Preliminary understanding of PostgreSQL (I)
还在用generator生成xxx管理系统的CRUD代码?来看看我是怎么写的
Isn't this another go bug?
如何阅读AI顶会论文?
5000 word analysis: the way of container security attack and defense in actual combat scenarios
Eureka's timedsupersortask class (periodic task with automatic interval adjustment)
Educoder web exercises -- text level semantic elements
Kubernetes' fast practice and core principle analysis
Educoder 表格标签-表格基本结构
How to read AI summit papers?
AGCO AI frontier promotion (6.21)