Seaborn is a Python data visualization library built on top of Matplotlib that provides an interface for creating informative and attractive statistical graphics. Below, I’ll provide you with 30 definitions, examples, and categorize them into different levels of complexity, ranging from basic to advanced, in categories like plotting, customization, and data manipulation.
Basic Level: Plotting Functions
- sns.set(): Set the default Seaborn aesthetics for your plots.
import seaborn as sns
sns.set()
- sns.lineplot(): Create a line plot.
sns.lineplot(x="x-axis", y="y-axis", data=data)
- sns.scatterplot(): Create a scatter plot.
sns.scatterplot(x="x-axis", y="y-axis", data=data)
- sns.barplot(): Create a bar plot.
sns.barplot(x="x-axis", y="y-axis", data=data)
- sns.countplot(): Create a count plot.
sns.countplot(x="category", data=data)
Intermediate Level: Customization
- sns.set_style(): Set the visual style of your plots.
sns.set_style("whitegrid")
- sns.set_context(): Set the context for the plot’s elements (e.g., paper, notebook).pythonCopy code
sns.set_context("talk")
- sns.color_palette(): Customize the color palette of your plots.
sns.color_palette("Set2")
- sns.lmplot(): Create a scatter plot with regression line.
sns.lmplot(x="x-axis", y="y-axis", data=data)
- sns.boxplot(): Create a box plot.
sns.boxplot(x="category", y="value", data=data)
Intermediate Level: Data Manipulation
- sns.load_dataset(): Load built-in example datasets.
data = sns.load_dataset("iris")
- sns.pairplot(): Create pairwise scatter plots for multiple variables.
sns.pairplot(data=data, hue="species")
- sns.heatmap(): Create a heatmap for correlation or categorical data.
sns.heatmap(data.corr(), annot=True)
- sns.catplot(): Create a categorical plot (e.g., swarm, violin).
sns.catplot(x="day", y="total_bill", data=tips, kind="swarm")
- sns.relplot(): Create a scatter or line plot with facets.
sns.relplot(x="x-axis", y="y-axis", data=data, col="category")
Advanced Level: Statistical Visualization
- sns.distplot(): Create a histogram with a kernel density estimate.
sns.distplot(data["column"])
- sns.jointplot(): Create a joint plot to visualize the relationship between two variables.
sns.jointplot(x="x-axis", y="y-axis", data=data, kind="hex")
- sns.regplot(): Create a regression plot with optional confidence intervals.
sns.regplot(x="x-axis", y="y-axis", data=data)
- sns.kdeplot(): Create a kernel density estimate plot.
sns.kdeplot(data["column"])
- sns.residplot(): Create a residual plot for linear regression.
s
ns.residplot(x="x-axis", y="residuals", data=data, lowess=True)
Advanced Level: Customization and Styling
- sns.set_palette(): Set a custom color palette.
sns.set_palette(["#FF0000", "#00FF00"])
- sns.set_theme(): Set a custom theme with various parameters.
sns.set_theme(style="whitegrid", palette="pastel", font_scale=1.5)
- sns.set_color_codes(): Customize color codes for Seaborn plots.
sns.set_color_codes(palette="deep")
- sns.despine(): Remove specific plot spines (axes lines).
s
ns.despine(left=True, bottom=True)
- sns.set_titles(): Set titles for facets in a multi-plot grid.
g = sns.catplot(x="x-axis", y="y-axis", data=data, col="category") g.set_titles("Category {col_name}")
Advanced Level: Data Manipulation and Styling
- sns.PairGrid(): Create a customized grid of subplots for pairwise relationships.
g = sns.PairGrid(data, hue="species") g.map_upper(sns.scatterplot) g.map_lower(sns.kdeplot) g.map_diag(sns.histplot)
- sns.FacetGrid(): Create a customized grid of subplots based on facets.
g = sns.FacetGrid(data, col="category", hue="species")
g.map(sns.scatterplot, "x-axis", "y-axis") g.add_legend()
- sns.clustermap(): Create a hierarchical cluster heatmap.
sns.clustermap(data.corr(), cmap="coolwarm")
- sns.PairGrid() with custom axes: Customize PairGrid with different plots on diagonal and off-diagonal.
g = sns.PairGrid(data, diag_sharey=False)
g.map_diag(sns.kdeplot)
g.map_upper(sns.scatterplot)
g.map_lower(sns.kdeplot, cmap="Blues_d")
- sns.JointGrid(): Create a customized grid for joint plots.
g = sns.JointGrid(x="x-axis", y="y-axis", data=data)
g.plot(sns.scatterplot, sns.histplot)