Matplotlib Mini Project (EDA charts pack)
Goal
Create a reusable set of plots you can apply to any dataset:
- Histogram (distribution)
- Bar chart (category counts)
- Line plot (trend)
- Scatter plot (relationship)
Sample dataset
Sample data
import pandas as pd
# Small example you can replace with any CSV
df = pd.DataFrame({
"date": pd.date_range("2025-01-01", periods=10, freq="D"),
"orders": [120, 140, 130, 160, 155, 170, 180, 175, 190, 200],
"city": ["Pune", "Delhi", "Pune", "Delhi", "Pune", "Mumbai", "Pune", "Delhi", "Mumbai", "Pune"],
"amount": [100, 140, 110, 160, 130, 90, 180, 150, 120, 200],
})Sample data
import pandas as pd
# Small example you can replace with any CSV
df = pd.DataFrame({
"date": pd.date_range("2025-01-01", periods=10, freq="D"),
"orders": [120, 140, 130, 160, 155, 170, 180, 175, 190, 200],
"city": ["Pune", "Delhi", "Pune", "Delhi", "Pune", "Mumbai", "Pune", "Delhi", "Mumbai", "Pune"],
"amount": [100, 140, 110, 160, 130, 90, 180, 150, 120, 200],
})1) Histogram
Histogram
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.hist(df["amount"], bins=8, edgecolor="black")
plt.title("Amount distribution")
plt.xlabel("Amount")
plt.ylabel("Count")
plt.tight_layout()
plt.show()Histogram
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.hist(df["amount"], bins=8, edgecolor="black")
plt.title("Amount distribution")
plt.xlabel("Amount")
plt.ylabel("Count")
plt.tight_layout()
plt.show()2) Bar chart (counts)
Bar counts
import matplotlib.pyplot as plt
counts = df["city"].value_counts()
plt.figure(figsize=(7, 4))
plt.bar(counts.index, counts.values)
plt.title("Orders count by city")
plt.xlabel("City")
plt.ylabel("Count")
plt.tight_layout()
plt.show()Bar counts
import matplotlib.pyplot as plt
counts = df["city"].value_counts()
plt.figure(figsize=(7, 4))
plt.bar(counts.index, counts.values)
plt.title("Orders count by city")
plt.xlabel("City")
plt.ylabel("Count")
plt.tight_layout()
plt.show()3) Line plot (trend)
Trend
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.plot(df["date"], df["orders"], marker="o")
plt.title("Orders trend")
plt.xlabel("Date")
plt.ylabel("Orders")
plt.xticks(rotation=20)
plt.tight_layout()
plt.show()Trend
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.plot(df["date"], df["orders"], marker="o")
plt.title("Orders trend")
plt.xlabel("Date")
plt.ylabel("Orders")
plt.xticks(rotation=20)
plt.tight_layout()
plt.show()4) Scatter plot
Scatter
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.scatter(df["orders"], df["amount"], alpha=0.7)
plt.title("Orders vs amount")
plt.xlabel("Orders")
plt.ylabel("Amount")
plt.tight_layout()
plt.show()Scatter
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.scatter(df["orders"], df["amount"], alpha=0.7)
plt.title("Orders vs amount")
plt.xlabel("Orders")
plt.ylabel("Amount")
plt.tight_layout()
plt.show()Deliverable
Save some plots with plt.savefig(...)plt.savefig(...) and reuse this structure for your datasets.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
