Statistical Charts with Seaborn
Seaborn sits on top of Matplotlib and makes beautiful statistical charts — straight from a DataFrame — in one line.
What you will learn
- Make a chart directly from a DataFrame
- Use a histogram and a scatter plot
- See why Seaborn is great for exploring
Prettier charts, less code
Seaborn is built on top of Matplotlib. It produces good-looking statistical charts with much less code, and — best of all — it works directly from a DataFrame by naming columns. It is the fastest way to explore data visually. By convention we import it as sns.
We will use this little table:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({
'size': [50, 60, 80, 100, 120], # house size
'price': [40, 55, 70, 95, 110] # house price
})Note: Output: (No output — just the table. Five houses, with a size and a price. As size goes up, price seems to go up too. Let us see it.)
A histogram — the shape of one column
A histogram shows how the values of one column are spread out — where most of them sit. Seaborn draws it from the column name.
sns.histplot(data=df, x='price')
plt.title('Distribution of Prices')
plt.show()Note: Output: (A chart with bars showing how many houses fall in each price band. The prices spread fairly evenly from 40 to 110.) A histogram answers “what do typical values look like, and are there outliers?” at a glance.
A scatter plot — two columns together
A scatter plot shows the relationship between two number columns — one dot per row. It is the best way to see if two things move together.
sns.scatterplot(data=df, x='size', y='price')
plt.title('Price vs Size')
plt.show()Note: Output: (Five dots climbing from lower-left to upper-right.) The dots rise together: bigger houses cost more. That upward pattern is a positive relationship — the idea behind correlation, coming up in the Stats unit.
| Seaborn function | Shows | Good for |
|---|---|---|
sns.histplot | Spread of one column | Seeing typical values |
sns.scatterplot | Two columns vs each other | Spotting relationships |
sns.barplot | Average per category | Comparing groups |
sns.boxplot | Spread per category | Comparing distributions |
Tip: Seaborn and Matplotlib work together: draw with Seaborn for looks, then use plt functions like plt.title() to fine-tune. You are not choosing one — you use both.
Q. Which Seaborn chart best shows whether two number columns move together?
✍️ Practice
- Use
sns.histplotto show the spread of one numeric column in a DataFrame. - Use
sns.scatterplotto plot two numeric columns and describe the pattern you see.
🏠 Homework
- On a real dataset, make a histogram of one column and a scatter plot of two columns. Write one sentence about what each chart tells you.