Learn how to visually explore and communicate data insights using Matplotlib and Seaborn in Python.
Data Visualization is the graphical representation of data to identify patterns, trends, and outliers.
Real-life example:
A business uses charts to understand monthly sales growth and customer behavior.
Matplotlib is the core plotting library in Python. It gives complete control over every element of a plot.
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Simple Line Plot")
plt.show()
Seaborn is built on top of Matplotlib and provides high-level, beautiful statistical visualizations.
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme()
data = [10, 20, 25, 30]
sns.lineplot(x=[1,2,3,4], y=data)
plt.show()
| Plot Type | Use Case |
|---|---|
| Line Plot | Trends over time |
| Bar Chart | Category comparison |
| Histogram | Distribution of data |
| Scatter Plot | Relationship between variables |
| Box Plot | Outliers and spread |
import pandas as pd
df = pd.DataFrame({
"Year": [2020, 2021, 2022],
"Sales": [200, 300, 450]
})
df.plot(x="Year", y="Sales", kind="bar")
plt.show()
plt.figure(figsize=(8,5))
plt.plot(x, y, color="green", marker="o")
plt.grid(True)
plt.show()