MatplotlibXBy @CodeWithMunnaX
Catalog
Track: Essential Charts
Categorical Data12 mins

11. Vertical & Horizontal Bar Charts

Bar charts are the gold standard for comparing quantities across distinct categories. Vertical bars work best for time/date categories, while horizontal bars (`barh`) are ideal when category names are long sentences.

Mental Model Intuition

Measuring the heights or lengths of solid pillars standing in a row.

Core Concepts & Mechanics

Horizontal Bar Charts (`barh`)Orientation

`plt.barh(categories, values)` flips the chart horizontally. Category labels read left-to-right effortlessly.

Use horizontal bars when category names exceed 8 characters to prevent overlapping text.
plt.barh(frameworks, popularity, color='#6366F1')

Common Beginner Mistakes & Pro Fixes

Avoid the top errors and bad plotting practices that trip up new Python developers

Troubleshooting

Quick Lesson Takeaways

  • `plt.bar(cats, vals)` draws vertical columns.
  • `plt.barh(cats, vals)` draws horizontal bars for long labels.
  • `color` accepts a single color or list of colors per bar.
Topic 11 • Python IDE
Python 3.12 • Matplotlib
Run Python code to inspect terminal output.

Real-World Datasets (1-Click Switcher)

Switch from abstract numbers to relatable Cricket, Cinema & Business charts

5 Curated Datasets

Hands-on Challenge: Draw Vertical Bars

+50 XP

Write Matplotlib code to solve the objective and see your live plot render

Objective Instructions:

Create a vertical bar chart for `items=['A', 'B', 'C']` and `vals=[15, 30, 25]` with `color='#6366F1'`.

Required Keywords:✓ plt.bar
Challenge Code Editor
Challenge Output GraphLive Vector Preview
Write code on the left to render live challenge plot
End of Lesson Knowledge Check

Quick Mini Quiz: 2 Concept Questions

Test your understanding to unlock the lesson completion badge

Q1

Which Matplotlib function is used to create a standard continuous 2D line plot?

Q2

What must you call after specifying label='...' so that the legend actually appears on the canvas?

0 of 2 answered