Mathew K Analytics

Lesson 14 · Data analytics zero to hero

Beautiful Charts with Seaborn in Python | Data Analytics #14

Video fourteen of the 30-part series: Seaborn, a higher-level charting library built directly on top of Matplotlib, for faster, more polished statistical…

What you'll learn

Datasets used in this lesson

Save these next to the notebook. In Google Colab, upload them with the 📁 icon on the left first.

📓 Full notebook

Download .ipynb

Data Analytics Zero to Hero, Video 14: Data Visualization with Seaborn#

  • Video fourteen of the 30-part series: Seaborn, a higher-level charting library built directly on top of Matplotlib, for faster, more polished statistical charts.
  • We're using the real Iris dataset, Ronald Fisher's classic 1936 flower measurements, one of the most famous real datasets in all of statistics.
  • Let's jump straight in.

Before You Start#

  • Open a new Jupyter Notebook in VS Code and select your Python interpreter as the kernel.
  • Install Seaborn if you haven't already: pip install seaborn.
  • Place iris.csv in the same folder as this notebook.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv('iris.csv')
print(df.shape)
print(df.head(3))
(150, 5)
   sepal_length  sepal_width  petal_length  petal_width species
0           5.1          3.5           1.4          0.2  setosa
1           4.9          3.0           1.4          0.2  setosa
2           4.7          3.2           1.3          0.2  setosa

Part 1: scatterplot with hue#

sns.scatterplot(data=df, x='petal_length', y='petal_width', hue='species')
plt.title('Real Petal Length vs. Width, by Species')
plt.show()
No description has been provided for this image

Part 2: Distributions with histplot and kdeplot#

sns.histplot(data=df, x='sepal_length', hue='species', kde=True)
plt.title('Real Sepal Length Distribution, by Species')
plt.show()
No description has been provided for this image
sns.kdeplot(data=df, x='petal_length', hue='species', fill=True)
plt.title('Real Petal Length Density, by Species')
plt.show()
No description has been provided for this image

Part 3: boxplot and violinplot#

sns.boxplot(data=df, x='species', y='petal_length')
plt.title('Real Petal Length by Species')
plt.show()
No description has been provided for this image
sns.violinplot(data=df, x='species', y='sepal_width')
plt.title('Real Sepal Width by Species')
plt.show()
No description has been provided for this image

Part 4: pairplot#

sns.pairplot(df, hue='species')
plt.show()
No description has been provided for this image

Part 5: Correlation Heatmap#

numeric_df = df.drop(columns='species')
corr = numeric_df.corr()
print(corr.round(2))
              sepal_length  sepal_width  petal_length  petal_width
sepal_length          1.00        -0.12          0.87         0.82
sepal_width          -0.12         1.00         -0.43        -0.37
petal_length          0.87        -0.43          1.00         0.96
petal_width           0.82        -0.37          0.96         1.00
sns.heatmap(corr, annot=True, cmap='coolwarm', center=0)
plt.title('Real Correlation Between Iris Measurements')
plt.show()
No description has been provided for this image

A Note on Styling#

sns.set_theme(style='whitegrid')
sns.scatterplot(data=df, x='sepal_length', y='sepal_width', hue='species')
plt.title('Themed Real Scatter Plot')
plt.show()
No description has been provided for this image

Wrap-Up: What You Learned#

  • scatterplot with hue, for fast, automatically colored and legended scatter plots.
  • histplot and kdeplot, for visualizing distributions, split by category.
  • boxplot and violinplot, for comparing a numeric column across categories.
  • pairplot, for surveying every numeric relationship in a dataset in one call.
  • A correlation heatmap, for scanning relationships between many columns at once.
  • set_theme, for a consistent, polished look across every chart.
  • All of it on the real, famous Iris dataset. This wraps up the visualization block. Video fifteen builds an interactive dashboard with Streamlit, turning charts like these into a real shareable app. Subscribe so it lands automatically see you there.

Found this useful?

All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.