- Seaborn 教程
- Seaborn - 首页
- Seaborn - 简介
- Seaborn - 环境设置
- 导入数据集和库
- Seaborn - 图形美观
- Seaborn - 调色板
- Seaborn - 直方图
- Seaborn - 核密度估计
- 可视化成对关系
- Seaborn - 绘制分类数据
- 观测值的分布
- Seaborn - 统计估计
- Seaborn - 绘制宽格式数据
- 多面板分类图
- Seaborn - 线性关系
- Seaborn - Facet Grid
- Seaborn - Pair Grid
- 函数参考
- Seaborn - 函数参考
- Seaborn 有用资源
- Seaborn - 快速指南
- Seaborn - 有用资源
- Seaborn - 讨论
Seaborn.set_style() 方法
Seaborn.set_style() 方法设置控制绘图整体风格的参数。此方法与 seaborn.axes_style() 方法紧密配合,因为它也检查网格是否默认启用,并使用其样式参数控制各种属性,例如背景颜色等。
可以通过 matplotlib rcParams 系统设置这些参数来控制绘图的整体样式。
语法
以下是 seaborn.set_style() 方法的语法:
seaborn.set_style(style=None, rc=None)
参数
以下是 seaborn.set_style() 方法的参数:
| 序号 | 参数及描述 |
|---|---|
| 1 | 样式 取值可以是 None、字典或 {darkgrid, whitegrid, dark, white, ticks} 中的一个,并确定参数字典或预配置样式的名称。 |
| 2 | Rc 取值为 rcdict,是一个可选参数,用于执行参数映射以覆盖预设 seaborn 样式字典中的值。这只会更新被视为样式定义一部分的参数。 |
现在我们将继续了解该方法并在示例中使用它。
示例 1
样式设置为“whitegrid”,并使用值列表绘制散点图。获得的绘图如下所示。
import seaborn as sns
import matplotlib.pyplot as plt
tips=sns.load_dataset("tips")
tips.head()
sns.set_style("whitegrid")
sns.scatterplot(x=["A", "B", "C"], y=[10, 30, 23])
plt.show()
输出
图形如下所示:
示例 2
在这个示例中,我们将看到另一种样式。dark 是一种可以设置的样式,获得的绘图将如下所示。
import seaborn as sns
import matplotlib.pyplot as plt
tips=sns.load_dataset("tips")
tips.head()
sns.set_style("dark")
sns.scatterplot(x=["A", "B", "C"], y=[10, 30, 23])
plt.show()
输出
获得的输出为:
示例 3
在这个示例中,我们将看到在设置样式时如何更改网格颜色和网格线样式。您需要像下面这样初始化它们,获得的图形将发生变化。
import seaborn as sns
import matplotlib.pyplot as plt
tips=sns.load_dataset("tips")
tips.head()
sns.set_style("darkgrid", {"grid.color": ".2", "grid.linestyle": ":"})
sns.lineplot(x=["man", "women", "child"], y=[45, 50, 20])
plt.show()
输出
获得的输出如下所示:
seaborn_themeing_introduction.htm
广告