Data Science

Bar Charts: Comparing Categories

SQL Mastery Team
May 29, 2026
5 min read

Welcome to **Day 128**. If the Line Chart is for "Time," the Bar Chart is for "Categories."

Vertical vs Horizontal

  • **Vertical (`plt.bar`)**: Best for small lists of categories (e.g., 3-5 regions).
  • **Horizontal (`plt.barh`)**: Best for long labels or many categories (e.g., Top 20 Best-Selling Books).
  • The Code

    categories = ['Electronics', 'Clothing', 'Home']

    counts = [450, 600, 300]

    plt.bar(categories, counts, color=['red', 'blue', 'green'])

    plt.title("Orders per Category")

    plt.show()

    Grouped Bar Charts

    Sometimes you want to compare categories *across another category* (e.g., Sales per region in 2023 vs 2024). This is where libraries like **Seaborn** start to shine!

    Your Task for Today

    Create a horizontal bar chart showing your 5 favorite movies and their IMDB ratings.

    *Day 129: Histograms: Seeing the Distribution.*

    Ready to put your knowledge into practice?

    Join SQL Mastery and learn through interactive exercises.