Saturday, 31 January 2026

๐Ÿ“Š Day 3: Horizontal Bar Chart in Python

๐Ÿ“Š 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:

LanguagePopularity
Python95
Java80
JavaScript85
C++70

๐Ÿง  Python Code: Horizontal Bar Chart Using Matplotlib

import matplotlib.pyplot as plt # Data languages = ['Python', 'Java', 'JavaScript', 'C++'] popularity = [95, 80, 85, 70] # Create horizontal bar chart plt.barh(languages, popularity) # Labels and title plt.xlabel('Popularity Score') plt.ylabel('Programming Languages') plt.title('Programming Language Popularity')
# Display chart
plt.show()

๐Ÿงฉ 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 TypeFunction
Vertical Bar (Column Chart)plt.bar()
Horizontal Bar Chartplt.barh()

๐Ÿ”‘ Key Takeaways

✔ Best for long category labels
✔ Improves readability
✔ Ideal for ranking data

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (190) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (28) Azure (8) BI (10) Books (262) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (299) Cybersecurity (29) data (1) Data Analysis (25) Data Analytics (18) data management (15) Data Science (256) Data Strucures (15) Deep Learning (106) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (18) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (54) Git (9) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (229) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (13) PHP (20) Projects (32) Python (1246) Python Coding Challenge (992) Python Mistakes (43) Python Quiz (406) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (46) Udemy (17) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)