Creating Statistical Visualizations with Seaborn
Seaborn builds on Matplotlib and makes it easier to create statistical charts. It works particularly well with Pandas DataFrames because columns can be assigned directly to chart variables.
Preparing a Dataset
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({
"Department": ["Sales", "IT", "HR", "Sales", "IT", "HR"],
"Experience": [2, 5, 3, 7, 8, 4],
"Salary": [35000, 65000, 40000, 60000, 85000, 45000]
})
sns.set_theme(style="whitegrid")
The dataset contains employee departments, years of experience, and salaries. It can be used to compare groups and investigate relationships.
Creating a Bar Plot
sns.barplot(data=df, x="Department", y="Salary")
plt.title("Average Salary by Department")
plt.show()
By default, Seaborn's barplot() estimates a summary statistic, typically the mean, for each category. It also displays uncertainty intervals by default. This differs from Matplotlib's bar(), which plots the values supplied directly.
Creating a Scatter Plot
sns.scatterplot(
data=df,
x="Experience",
y="Salary",
hue="Department"
)
plt.title("Experience vs Salary")
plt.show()
The hue parameter assigns different visual colors to categories, helping identify group-level patterns.
Creating a Box Plot
sns.boxplot(data=df, x="Department", y="Salary")
plt.title("Salary Distribution by Department")
plt.show()
A box plot displays the median, quartiles, and potential outliers. It is useful when comparing how numerical values vary across groups.
Python for Data Science
Vishalini A








