Advanced Plot Types With Seaborn
Advanced Plot Types With Seaborn
These include:
1|Page
Example 1: Visualizing Univariate Distribution
Output
2|Page
Creating Pair Plots to Visualize Pairwise Relationships
# Example DataFrame
data = {
'A': [1, 2, 3, 4, 5],
'B': [5, 4, 3, 2, 1],
'C': [1, 3, 5, 3, 1]
}
df = pd.DataFrame(data)
Output
3|Page
Here is the breakdown of the code step-by-step:
1. Import Libraries:
• seaborn as sns: Seaborn is a statistical data visualization library
based on Matplotlib. It provides a high-level interface for drawing
attractive and informative statistical graphics.
• pandas as pd: Pandas is a powerful data manipulation and analysis
library for Python. It provides data structures like DataFrames, which
are perfect for handling tabular data.
• matplotlib.pyplot as plt: Matplotlib is a plotting library for Python.
Pyplot is a module in Matplotlib that provides a MATLAB-like
interface for plotting.
2. Create a DataFrame:
• A dictionary data is defined with three keys ('A', 'B', and 'C') each
associated with a list of numbers.
• pd.DataFrame(data): This converts the dictionary into a Pandas
DataFrame. The DataFrame df will have three columns ('A', 'B', and
'C') with the corresponding values.
Here are some additional parameters you can use to customize the pairplot:
4|Page
Generating Heatmaps for Correlation and Categorical Data
# Create a heatmap
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm',
vmin=-1, vmax=1)
plt.title('Correlation Heatmap')
plt.show()
5|Page
Output
o vmin=-1, vmax=1: Set the range of values for the color map to
indicate the correlation strength from -1 (strong negative
correlation) to 1 (strong positive correlation).
6|Page
• plt.title('Correlation Heatmap'): Adds a title to the heatmap plot.
Categorical Data Heatmap: This type of heatmap is used when you have
categorical data and want to visualize how different categories are
distributed across numerical values. It shows counts or frequencies of
categories for each value, providing insights into distribution patterns.
Output
7|Page
Here is the breakdown of the code step-by-step:
8|Page