๐ Day 2: Bar Chart in Python
๐ What is a Bar Chart?
A bar chart is used to compare values across different categories.
Each bar represents:
-
A category on one axis
-
A numeric value on the other axis
The length or height of the bar shows how big the value is.
✅ When Should You Use a Bar Chart?
Use a bar chart when:
-
Data is categorical
-
You want to compare counts, totals, or averages
-
Order of categories does not depend on time
Real-world examples:
-
Sales by product
-
Students in each class
-
Votes per candidate
-
Marks per subject
❌ Bar Chart vs Line Chart
| Bar Chart | Line Chart |
|---|---|
| Categorical data | Time-based data |
| Compares values | Shows trends |
| Bars do not touch | Points are connected |
๐ Example Dataset
Let’s compare sales of different products:
| Product | Sales |
|---|---|
| Laptop | 120 |
| Mobile | 200 |
| Tablet | 90 |
| Headphones | 150 |
๐ง Python Code: Bar Chart Using Matplotlib
๐งฉ Code Explanation (Simple)
plt.bar() → creates the bar chart
products → categories on x-axis
sales → numerical values on y-axis
xlabel() & ylabel() → axis labels
title() → chart heading
๐ Important Points to Remember
✔ Bar charts compare categories
✔ Bars do not touch
✔ Simple and easy to interpret
✔ Widely used in reports and dashboards
.png)

0 Comments:
Post a Comment