Learn Python Programming  /  Data Visualization  /  Seaborn Plots

Seaborn Plots

Seaborn builds on Matplotlib to make statistical charts easier and more attractive by default — especially when your data already lives in a pandas DataFrame.

Installing and Basic Setup

R Code
pip install seaborn

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")  # nicer default styling for every plot after this

Scatter Plot with a Trend Line: sns.regplot()

R Code
df = pd.DataFrame({"height": [150,160,165,170,180],
                   "weight": [50,55,60,65,75]})

sns.regplot(data=df, x="height", y="weight")
plt.show()

Bar Plot with Automatic Confidence Intervals: sns.barplot()

R Code
sns.barplot(data=df, x="group", y="score")
plt.show()
💡 Tip
sns.barplot() automatically calculates and draws the mean of each group, plus a confidence-interval error bar - something you would need several extra lines of matplotlib code to reproduce manually.

Correlation Heatmap: sns.heatmap()

R Code
numeric_df = pd.DataFrame({
    "study_hours": [3,4,5,6,7],
    "sleep_hours": [8,7,7,6,6],
    "exam_score":  [60,68,75,85,90]
})

sns.heatmap(numeric_df.corr(), annot=True, cmap="coolwarm")
plt.show()

Advanced: Pair Plot for Exploring Many Variables at Once

🚀 Advanced Example
sns.pairplot() draws every pairwise scatter plot (and each variable\'s own distribution) for a whole DataFrame at once - an excellent first step for exploring a new dataset.
R Code
sns.pairplot(numeric_df)
plt.show()

Key Points

  • Seaborn plots work directly with a pandas DataFrame using column names as arguments.
  • sns.regplot() adds a fitted trend line automatically; sns.barplot() adds confidence intervals automatically.
  • sns.heatmap(df.corr(), annot=True) is the fastest way to visualise a correlation matrix.
  • sns.pairplot(df) explores every pairwise relationship in a dataset in one call.