Types Of Seaborn Plots
Seaborn is a Python data visualization library based on Matplotlib that provides a high-level interface for drawing attractive and informative statistical graphics. It is built on top of matplotlib and integrates with pandas data structures making it an ideal choice for visualizing data from data frames and arrays.
Types Of Seaborn Plots
Below are the plots those we discuss in this article.
- Relational Plots in Seaborn
- Categorical Plots in Seaborn
- Distribution Plots in Seaborn
- Matrix Plots in Seaborn
- Pair Grid in Seaborn
Relational Plots in Seaborn
Scatter Plot , Line Plot and Relational Plot are contained in the category of Relational Plots in Seaborn.
1. Scatter Plot
A scatter plot is a type of graph that uses Cartesian coordinates to display values for two variables for a set of data. Points on the plot indicate the values of the variables, allowing for visualization of any correlation or pattern.
We create a scatter plot using the "total_bill" column for the x-axis and the "tip" column for the y-axis from the "tips" dataset using the sns.scatterplot(data=tips, x="total_bill", y="tip")
function
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.scatterplot(data=tips, x="total_bill", y="tip")
plt.show()
Output:

2. Line plot
A line plot is a type of graph that displays data points connected by straight lines, showing trends over a continuous interval or time period. It is useful for visualizing changes and trends in data over time.
We can create a line plot using the "size" column (number of people at the table) for the x-axis and the "tip" column for the y-axis from the "tips" dataset using sns.lineplot(data=tips, x="size", y="tip").
This visualizes the relationship between the size of the party and the tip amount.
import seaborn as sns
import matplotlib.pyplot as plt
sns.lineplot(data=tips, x="size", y="tip")
plt.show()
Output:

3. Relational Plot (relplot):
A relational plot (relplot) is a versatile function in seaborn for creating scatter and line plots, with additional capabilities for faceting data into multiple subplots. It simplifies the creation of complex visualizations by handling various plot types and layouts automatically.
A relational plot using Seaborn to visualize some data. This code creates a relational plot that uses total_bill and tip from the tips dataset, with points colored by the smoker variable.
import seaborn as sns
import matplotlib.pyplot as plt
sns.load_dataset("tips")
sns.relplot(data=tips, x="total_bill", y="tip", hue="smoker")
plt.show()
Output:

Categorical Plots in Seaborn
Bar Plot ,Count Plot, Box Plot , Violin Plot , Strip Plot , Swarm Plot are some of the categorical plots in Seaborn.
1. Bar Plot (barplot):
A bar plot (barplot) displays categorical data with rectangular bars where the length of each bar represents the value of the corresponding category. It is useful for comparing quantities across different categories. Let's show the average total_bill for each day through bar plot.
import seaborn as sns
import matplotlib.pyplot as plt
sns.barplot(data=tips, x="day", y="total_bill")
plt.show()
Output:

2. Count Plot (countplot):
A count plot (countplot) is a bar plot that shows the frequency of occurrences for each category in a categorical variable. It visualizes the count of each unique value in the data. The below code generates a count plot showing the number of occurrences for each day in the tips dataset.
import seaborn as sns
import matplotlib.pyplot as plt
sns.countplot(data=tips, x="day")
plt.show()
Output:

3. Box Plot (boxplot):
A box plot displays the distribution of a dataset through its quartiles, highlighting the median, interquartile range and potential outliers. It provides a visual summary of the data's central tendency, dispersion, and skewness.
This code creates a box plot using the tips dataset, displaying the distribution of total_bill for each day.
import seaborn as sns
import matplotlib.pyplot as plt
sns.boxplot(data=tips, x="day", y="total_bill")
plt.show()
Output:

4. Violin Plot (violinplot):
A violin plot (violinplot) combines a box plot with a kernel density plot, showing the distribution, probability density, and central tendencies of the data. It provides a detailed view of the data's distribution, highlighting variations and multimodalities.
Th below code creates a violin plot showing the distribution of total_bill for each day in the tips dataset.
import seaborn as sns
import matplotlib.pyplot as plt
sns.violinplot(data=tips, x="day", y="total_bill")
plt.show()
Output:

5. Strip Plot (stripplot):
A strip plot (stripplot) displays individual data points for one or more categorical variables, often overlaid on a box or violin plot. It shows the distribution and concentration of data points, highlighting any potential outliers. Below code generates a strip plot showing all total_bill values for each day in the tips dataset as individual points.
import seaborn as sns
import matplotlib.pyplot as plt
sns.stripplot(data=tips, x="day", y="total_bill")
plt.show()
Output:

6. Swarm Plot
A swarm plot displays individual data points for one or more categorical variables, similar to a strip plot, but adjusts points to avoid overlap. It provides a clear view of the distribution and density of the data. This creates a swarm plot showing the distribution of total_bill for each day with non-overlapping points.
import seaborn as sns
import matplotlib.pyplot as plt
sns.swarmplot(data=tips, x="day", y="total_bill")
plt.show()
Output

Distribution Plots in Seaborn
1. Histogram (histplot):
A histogram (histplot) displays the distribution of a continuous variable by dividing data into bins and plotting the frequency of data points in each bin. It provides insights into the data's central tendency, dispersion, and shape. Let's generate a histogram showing the distribution of total_bill in the tips dataset.
import seaborn as sns
import matplotlib.pyplot as plt
sns.histplot(data=tips, x="total_bill")
plt.show()
Output

2. Kernel Density Estimate Plot (kdeplot):
A kernel density estimate plot (kdeplot) visualizes the probability density function of a continuous variable by smoothing the histogram with a kernel function. It provides a smooth representation of the data's distribution, allowing for better understanding of its shape and characteristics.KDE plot which is a smoothed version of the histogram showing the distribution of total_bill.
import seaborn as sns
import matplotlib.pyplot as plt
sns.kdeplot(data=tips, x="total_bill")
plt.show()
Output

3. Distribution Plot (displot):
A distribution plot (displot) is a versatile seaborn function that allows for visualization of univariate distributions. It can combine histograms, kernel density estimates, and rug plots to provide insights into the distribution of a single variable.
import seaborn as sns
import matplotlib.pyplot as plt
sns.displot(data=tips, x="total_bill", kind="kde")
plt.show()
Output

4. Empirical Cumulative Distribution Function Plot (ecdfplot):
An empirical cumulative distribution function plot (ecdfplot) displays the cumulative distribution of a continuous variable based on the observed data points. It shows how the data is spread across different percentiles and can be useful for comparing distributions or assessing goodness-of-fit.
This code creates an Empirical Cumulative Distribution Function (ECDF) plot showing the proportion of data points less than or equal to each total_bill value.
import seaborn as sns
import matplotlib.pyplot as plt
sns.ecdfplot(data=tips, x="total_bill")
plt.show()
Output

5. Rug Plot (rugplot):
A rug plot (rugplot) is a simple plot that displays individual data points along a single axis, usually the x-axis as small lines or ticks. It provides a visual representation of the data distribution and density, often used in combination with other types of plots like histograms or KDE plots. Let's generates a rug plot which show individual total_bill values as small vertical lines along the x-axis.
import seaborn as sns
import matplotlib.pyplot as plt
sns.rugplot(data=tips, x="total_bill")
plt.show()
Output

Matrix Plots in Seaborn
1. Heatmap (heatmap):
A heatmap (heatmap) is a graphical representation of data where values in a matrix are represented as colors. It's often used to visualize the magnitude of values in a matrix, allowing patterns and correlations to be easily identified. Below code creates a heatmap using the flights dataset and show the number of passengers each month over the years.
import seaborn as sns
import matplotlib.pyplot as plt
flights = sns.load_dataset("flights")
flights_pivot = flights.pivot(index="month", columns="year", values="passengers")
sns.heatmap(flights_pivot, annot=True, fmt="d", cmap="YlGnBu")
plt.show()
Output

2. Cluster Map (clustermap):
A cluster map (clustermap) is a heatmap that organizes rows and columns of a dataset based on their similarity, often using hierarchical clustering. It's useful for identifying patterns and relationships in complex datasets by grouping similar rows and columns together. Let's see how to generate cluster map which clusters both rows and columns based on similarity, using the flights dataset.
import seaborn as sns
import matplotlib.pyplot as plt
flights = sns.load_dataset("flights")
flights_pivot = flights.pivot(index="month", columns="year", values="passengers")
sns.clustermap(flights_pivot, cmap="viridis", standard_scale=1)
plt.show()
Output

Pair Grid (PairGrid) in Seaborn
1. Pair Plot (pairplot):
A pair plot (pairplot) creates a grid of scatterplots and histograms for each pair of variables in a dataset, allowing for visual exploration of relationships and distributions between variables. It's particularly useful for identifying patterns and correlations in multivariate data.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.pairplot(tips, hue="smoker", palette="coolwarm")
plt.show()
Output:

The above plot showing pairwise relationships between all numerical variables in the tips dataset.