β Learning Matplotlib (All Charts Explained!)
Today, I worked with Matplotlib, the most fundamental Python library for data visualization.
It allows you to turn raw data into meaningful graphs that help in understanding patterns, trends, and insights.
π₯ What I Learned β Matplotlib Chart Types
Below are the essential chart types every Data Analyst should know:
1οΈβ£ Line Chart
Used to show trends over time.
Use case: Monthly sales trend.
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [10, 20, 15, 25, 30]
plt.plot(x, y)
plt.title("Line Chart")
plt.xlabel("Months")
plt.ylabel("Sales")
plt.show()
2οΈβ£ Bar Chart
Used to compare categories.
categories = ["A", "B", "C"]
values = [20, 35, 30]
plt.bar(categories, values)
plt.title("Bar Chart")
plt.show()
3οΈβ£ Histogram
Shows the distribution of data.
data = [22,25,29,21,28,30,27,26,32,24]
plt.hist(data, bins=5)
plt.title("Histogram")
plt.show()
4οΈβ£ Scatter Plot
Used to find the relationship between two variables.
x = [1,2,3,4,5]
y = [5,20,15,25,30]
plt.scatter(x, y)
plt.title("Scatter Plot")
plt.show()
5οΈβ£ Pie Chart
Used to show parts of a whole.
sizes = [30,25,20,25]
labels = ["A","B","C","D"]
plt.pie(sizes, labels=labels, autopct="%1.1f%%")
plt.title("Pie Chart")
plt.show()
6οΈβ£ Box Plot
Helps identify data spread and outliers.
data = [22,25,29,21,28,30,27,26,32,24]
plt.boxplot(data)
plt.title("Box Plot")
plt.show()
7οΈβ£ Area Chart
Shows cumulative progress.
x = [1,2,3,4,5]
y = [3,8,2,10,5]
plt.fill_between(x, y)
plt.title("Area Chart")
plt.show()
8οΈβ£ Heatmap (Using seaborn for better visuals)
Helps show patterns between variables.
import seaborn as sns
import numpy as np
data = np.random.rand(5,5)
sns.heatmap(data, annot=True)
plt.title("Heatmap")
plt.show()
β¨ Additional Things I Practiced
- Customized chart colors and styles
- Adjusted figure sizes
- Added labels, legends, and titles
- Created multiple plots using
subplot() - Saved charts as images
These visualizations help communicate insights clearly β a must-have skill for Data Analysts.
π Consistency is my strength. Day 64 completed.
RamyaAnalyticsJourney
π GitHub Link:
https://github.com/ramyacse21/matplotlib_python/blob/main/practice%20matplotlib%20pie%20chart.py
https://github.com/ramyacse21/matplotlib_python/blob/main/practice%20matplotlib.py
Top comments (0)