A chart reveals what a table hides. Plot distributions, relationships, and correlations with Matplotlib and Seaborn to understand data before you model it.
Why: exploratory plots answer the first questions about any dataset — how is a value distributed, and how do two values relate — before you commit to a model. When: histogram for one variable’s distribution, scatter for the relationship between two. Where: Matplotlib is the engine; you call it directly or through pandas/Seaborn.
pip install matplotlib seabornWhy: a histogram shows the shape of one feature (skew, outliers, multiple peaks) and a scatter shows whether two features move together — both guide preprocessing and model choice. When: plot every important feature’s distribution during exploration. Where: pandas plots straight off a DataFrame for quick looks.
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({"age": [22, 25, 29, 35, 41, 52, 60],
"income": [30, 35, 45, 60, 80, 90, 110]})
df["age"].plot(kind="hist", bins=5, title="Age distribution")
plt.show()
df.plot(kind="scatter", x="age", y="income", title="Income vs age")
plt.show()Why: Seaborn wraps Matplotlib with concise, good-looking statistical charts — one line gives you a regression scatter, a box plot by category, or a correlation heatmap. When: use it for the exploratory plots you make dozens of times. Where: it takes a DataFrame and column names directly, so there is little boilerplate.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips") # a built-in example dataset
sns.boxplot(data=tips, x="day", y="total_bill") # distribution per category
plt.show()
# Correlation heatmap — spot related features at a glance:
sns.heatmap(tips.corr(numeric_only=True), annot=True, cmap="coolwarm")
plt.show()Why: before modeling, a correlation matrix shows which features relate to the target (candidates for the model) and which relate to each other (redundant, a source of multicollinearity). When: run it during exploration to prune and prioritize features. Where: correlation only captures linear relationships — pair it with scatter plots for the full picture.
import seaborn as sns, matplotlib.pyplot as plt
corr = tips.corr(numeric_only=True)
print(corr["total_bill"].sort_values(ascending=False)) # what relates to the target
# Strong feature-to-feature correlation (e.g. > 0.9) means redundancy —
# consider dropping one, which the Data Cleaning course covers as
# dimensionality reduction.