๐ Day 3: Horizontal Bar Chart in Python
๐ What is a Horizontal Bar Chart?
A horizontal bar chart displays bars from left to right instead of bottom to top.
It is especially useful when:
-
Category names are long
-
There are many categories
-
You want to show rankings clearly
✅ When Should You Use a Horizontal Bar Chart?
Use it when:
-
Labels don’t fit well on the x-axis
-
You want easy comparison across categories
-
Displaying Top-N lists
Real-world examples:
-
Most popular programming languages
-
Top-selling products
-
Employee performance ranking
๐ Example Dataset
Let’s compare popularity of programming languages:
| Language | Popularity |
|---|---|
| Python | 95 |
| Java | 80 |
| JavaScript | 85 |
| C++ | 70 |
๐ง Python Code: Horizontal Bar Chart Using Matplotlib
๐งฉ Code Explanation (Simple)
plt.barh() → creates a horizontal bar chart
-
Categories appear on the y-axis
-
Values appear on the x-axis
-
Bars grow left to right
๐ Horizontal Bar vs Vertical Bar Chart
| Chart Type | Function |
|---|---|
| Vertical Bar (Column Chart) | plt.bar() |
| Horizontal Bar Chart | plt.barh() |
๐ Key Takeaways
✔ Best for long category labels
✔ Improves readability
✔ Ideal for ranking data
.png)

0 Comments:
Post a Comment