0
# Seaborn
1
2
A comprehensive statistical data visualization library for Python built on top of matplotlib that provides a high-level interface for creating attractive and informative statistical graphics. Seaborn offers specialized plotting functions for statistical relationships, categorical data visualization, distribution analysis, and matrix visualizations with intelligent default styling, color palette management, and seamless integration with pandas DataFrames.
3
4
## Package Information
5
6
- **Package Name**: seaborn
7
- **Language**: Python
8
- **Installation**: `pip install seaborn`
9
10
## Core Imports
11
12
```python
13
import seaborn as sns
14
```
15
16
Common pattern with matplotlib:
17
18
```python
19
import seaborn as sns
20
import matplotlib.pyplot as plt
21
```
22
23
## Basic Usage
24
25
```python
26
import seaborn as sns
27
import matplotlib.pyplot as plt
28
import pandas as pd
29
30
# Load built-in dataset
31
tips = sns.load_dataset("tips")
32
33
# Create a simple scatter plot
34
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
35
plt.show()
36
37
# Create a regression plot
38
sns.regplot(data=tips, x="total_bill", y="tip")
39
plt.show()
40
41
# Set seaborn theme for better styling
42
sns.set_theme(style="whitegrid")
43
```
44
45
## Architecture
46
47
Seaborn provides two complementary plotting interfaces:
48
49
- **Figure-level functions**: Create entire figures with subplots (e.g., `relplot`, `catplot`, `displot`)
50
- **Axes-level functions**: Draw plots on specific matplotlib axes (e.g., `scatterplot`, `boxplot`, `histplot`)
51
52
The library integrates seamlessly with matplotlib for customization and pandas for data handling, making it ideal for statistical analysis workflows.
53
54
## Capabilities
55
56
### Statistical Relationship Plots
57
58
Visualize relationships between variables using scatter plots, line plots, and regression analysis with support for semantic groupings and multi-panel layouts.
59
60
```python { .api }
61
def relplot(data, x, y, hue=None, style=None, size=None, kind="scatter", **kwargs): ...
62
def scatterplot(data, x, y, hue=None, style=None, size=None, **kwargs): ...
63
def lineplot(data, x, y, hue=None, style=None, size=None, **kwargs): ...
64
def regplot(data, x, y, **kwargs): ...
65
def lmplot(data, x, y, hue=None, **kwargs): ...
66
def residplot(data, x, y, **kwargs): ...
67
```
68
69
[Relational Plots](./relational-plots.md)
70
71
### Categorical Data Visualization
72
73
Display categorical data through strip plots, swarm plots, box plots, violin plots, bar plots, and count plots with statistical summaries and confidence intervals.
74
75
```python { .api }
76
def catplot(data, x, y, hue=None, kind="strip", **kwargs): ...
77
def stripplot(data, x, y, hue=None, **kwargs): ...
78
def swarmplot(data, x, y, hue=None, **kwargs): ...
79
def boxplot(data, x, y, hue=None, **kwargs): ...
80
def violinplot(data, x, y, hue=None, **kwargs): ...
81
def barplot(data, x, y, hue=None, estimator=None, **kwargs): ...
82
def countplot(data, x, hue=None, **kwargs): ...
83
```
84
85
[Categorical Plots](./categorical-plots.md)
86
87
### Distribution Analysis
88
89
Analyze and visualize statistical distributions using histograms, kernel density estimation, empirical CDFs, and rug plots with univariate and bivariate support.
90
91
```python { .api }
92
def displot(data, x, y=None, hue=None, kind="hist", **kwargs): ...
93
def histplot(data, x, y=None, hue=None, **kwargs): ...
94
def kdeplot(data, x, y=None, hue=None, **kwargs): ...
95
def ecdfplot(data, x, hue=None, **kwargs): ...
96
def rugplot(data, x, y=None, **kwargs): ...
97
```
98
99
[Distribution Plots](./distribution-plots.md)
100
101
### Matrix Visualization
102
103
Create heatmaps and clustered heatmaps for correlation matrices, pivot tables, and hierarchical clustering visualization.
104
105
```python { .api }
106
def heatmap(data, **kwargs): ...
107
def clustermap(data, **kwargs): ...
108
```
109
110
[Matrix Plots](./matrix-plots.md)
111
112
### Multi-Panel Grids
113
114
Build complex multi-panel figures with FacetGrid, PairGrid, and JointGrid for comprehensive data exploration and comparison across subsets.
115
116
```python { .api }
117
class FacetGrid:
118
def __init__(self, data, **kwargs): ...
119
def map(self, func, *args, **kwargs): ...
120
121
class PairGrid:
122
def __init__(self, data, **kwargs): ...
123
def map(self, func, **kwargs): ...
124
125
def pairplot(data, **kwargs): ...
126
def jointplot(data, x, y, kind="scatter", **kwargs): ...
127
```
128
129
[Grid Plots](./grid-plots.md)
130
131
### Styling and Themes
132
133
Configure plot aesthetics, themes, color palettes, and plotting contexts with extensive customization options for publication-quality graphics.
134
135
```python { .api }
136
def set_theme(context="notebook", style="darkgrid", palette="deep", **kwargs): ...
137
def set_style(style, rc=None): ...
138
def set_context(context, font_scale=1, rc=None): ...
139
def set_palette(palette, n_colors=None, desat=None): ...
140
def color_palette(palette=None, n_colors=None, desat=None): ...
141
def reset_defaults(): ...
142
def reset_orig(): ...
143
```
144
145
[Styling and Themes](./styling-themes.md)
146
147
### Color Palettes
148
149
Generate and customize color palettes including sequential, diverging, qualitative, and perceptually uniform palettes with built-in colormap support.
150
151
```python { .api }
152
def husl_palette(n_colors=6, h=0.01, s=0.9, l=0.65): ...
153
def cubehelix_palette(n_colors=6, start=0, rot=0.4, gamma=1.0, hue=0.8, light=0.85, dark=0.15): ...
154
def dark_palette(color, n_colors=6, reverse=False, as_cmap=False): ...
155
def light_palette(color, n_colors=6, reverse=False, as_cmap=False): ...
156
def diverging_palette(h_neg, h_pos, s=75, l=50, n=6, center="light"): ...
157
```
158
159
[Color Palettes](./color-palettes.md)
160
161
### Utilities and Helpers
162
163
Essential utility functions for plot customization, data loading, color manipulation, and legend management.
164
165
```python { .api }
166
def despine(fig=None, ax=None, top=True, right=True, left=False, bottom=False): ...
167
def load_dataset(name, cache=True, data_home=None, **kwargs): ...
168
def move_legend(obj, loc, **kwargs): ...
169
def get_dataset_names(): ...
170
```
171
172
[Utilities](./utilities.md)
173
174
### Interactive Color Palette Widgets
175
176
Interactive Jupyter widgets for creating and customizing color palettes in real-time with GUI controls for palette selection and parameter adjustment.
177
178
```python { .api }
179
def choose_colorbrewer_palette(data_type, as_cmap=False): ...
180
def choose_dark_palette(input="husl", as_cmap=False): ...
181
def choose_light_palette(input="husl", as_cmap=False): ...
182
def choose_diverging_palette(as_cmap=False): ...
183
def choose_cubehelix_palette(as_cmap=False): ...
184
```
185
186
[Interactive Widgets](./interactive-widgets.md)
187
188
### Objects Interface
189
190
Declarative, object-oriented interface for creating statistical graphics following Grammar of Graphics principles with composable classes for flexible visualization construction.
191
192
```python { .api }
193
class Plot:
194
def __init__(self, *args, data=None, **variables): ...
195
def add(self, mark, *transforms, **kwargs): ...
196
def facet(self, col=None, row=None, **kwargs): ...
197
def scale(self, **scales): ...
198
199
# Mark classes
200
class Dot(Mark): ...
201
class Line(Mark): ...
202
class Bar(Mark): ...
203
204
# Statistical transforms
205
class Hist(Stat): ...
206
class KDE(Stat): ...
207
class Agg(Stat): ...
208
209
# Positional adjustments
210
class Jitter(Move): ...
211
class Dodge(Move): ...
212
class Stack(Move): ...
213
```
214
215
[Objects Interface](./objects-interface.md)
216
217
## Types
218
219
Core types used throughout the seaborn API:
220
221
```python { .api }
222
# Data input types
223
DataFrame = pandas.DataFrame
224
Series = pandas.Series
225
Array = numpy.ndarray | list
226
227
# Color specifications
228
ColorSpec = str | tuple | list # Color names, hex codes, RGB tuples
229
PaletteSpec = str | list | dict # Palette names or color lists
230
231
# Plot objects
232
FacetGrid = seaborn.axisgrid.FacetGrid
233
PairGrid = seaborn.axisgrid.PairGrid
234
JointGrid = seaborn.axisgrid.JointGrid
235
```