当前位置:网站首页>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·

一个只分享干货的
生信公众号
边栏推荐
- Eureka的TimedSupervisorTask类(自动调节间隔的周期性任务)
- 【升级版学生信息管理系统】+文件操作+更多细节
- Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes for Dense Object Detection
- UVA1203 Argus
- 显示Oracle某一张表的所有索引
- 机器学习探索共价键碳的亚稳态相图,未来可用于发现或设计亚稳态材料
- Is the live interactive function of the applet running in the app?
- Deep understanding of convolution in convolution neural network
- TOOD: Task-aligned One-stage Object Detection
- Educator web exercises - grouping elements
猜你喜欢
![[Anxin cup 2019]easy_ web-1](/img/1d/f164c220f6c8e98b981ef79b0e96bc.png)
[Anxin cup 2019]easy_ web-1

Reading notes on how to connect the Internet ADSL

Pretraining Weekly No. 50: No Decode converter, neural prompt search, gradient Space reduction

Educoder Web练习题---分组元素
MySQL约束(创建表时的各种条件说明)

SCCM creates a client collection based on the installed app and periodically pushes application updates

Centos7 deploying MySQL environment

应用配置管理,基础原理分析

Voltage detection and current detection based on stm32

Eureka's timedsupersortask class (periodic task with automatic interval adjustment)
随机推荐
Tami dog sharing: the way of property right transaction and the significance of data-based property right transaction market
2022年中国手机银行年度专题分析
uva11995
Educoder Web练习题---交互元素
Not only zero:bmtrain technology principle analysis
Distributed transaction processing scheme big PK
AGCO AI frontier promotion (6.21)
Educator table labels - settings for Advanced Table Styles
Using slurm cluster computing node debugger in vscode
【升级版学生信息管理系统】+文件操作+更多细节
Pretraining Weekly No. 50: No Decode converter, neural prompt search, gradient Space reduction
uva11292
Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway
Apache ShardingSphere 5.1.2 发布|全新驱动 API + 云原生部署,打造高性能数据网关
塔米狗分享:产权交易的方式及其产权交易市场数据化意义
Educator web exercise - grouping form elements
Libcef common concepts framework features
华为云发布桌面IDE-CodeArts
Nouveau partage de l'expérience de travail à domicile
uva11729