Bar Charts, Horizontal Bars & Stacked Bars0%
Bar Charts, Horizontal Bars & Stacked Bars
Beginner12 min read•Updated: Jul 11, 2026
Bar Charts, Horizontal Bars & Stacked Bars
Reading Time: 8 Mins | Level: Intermediate
1. Comparing Discrete Categories
While line charts represent continuous trends, Bar Charts are designed to compare discrete categories (e.g., Sales by Department, Revenue by Region, Traffic by Channel).
2. Vertical vs Horizontal Bar Charts
- Vertical Bars (
ax.bar): Best when categories are few (3 to 7) and have short names. - Horizontal Bars (
ax.barh): Best when comparing many categories (8+) or when category labels are long (e.g., "Customer Relationship Management Department").
Python
import matplotlib.pyplot as plt
cities = ['Mumbai', 'Delhi', 'Bengaluru', 'Hyderabad', 'Chennai']
sales = [1420, 1380, 1150, 890, 780]
fig, ax = plt.subplots(figsize=(9, 4.5))
# Horizontal bar chart sorted by value
ax.barh(cities, sales, color='#0284c7', height=0.6)
ax.set_title('Top Indian Metro Markets by Revenue (Cr INR)')
ax.set_xlabel('Revenue (in Crores)')
ax.invert_yaxis() # Puts the highest value at the top!
# Add direct data value labels on bars
for idx, val in enumerate(sales):
ax.text(val + 20, idx, f"₹{val} Cr", va='center', fontweight='bold', fontsize=10)
plt.show()
Interactive Quiz
Multiple Choice Questions
Question 1
Which Matplotlib method renders a horizontal bar chart?
Question 2
Why are horizontal bar charts strongly recommended when category labels are lengthy?
Question 3
What does calling
ax.invert_yaxis() do on a horizontal bar chart?Question 4
How do you construct a stacked bar chart in Matplotlib?
Question 5
What is the recommended best practice for ordering categories in a comparison bar chart?
Next Lesson
Histograms, Bins & Probability Density
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Line Plots, Markers, Line Styles & Multiple Series | Histograms, Bins & Probability Density |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.