Saturday, 31 January 2026

๐Ÿ“Š Day 6: Percentage Stacked Bar Chart in Python

 

๐Ÿ”น What is a Percentage Stacked Bar Chart?

A Percentage Stacked Bar Chart displays data where each bar represents 100% of the total, and each segment shows the percentage contribution of a category to that total.
Instead of absolute values, it focuses on proportions.


๐Ÿ”น When Should You Use It?

Use a percentage stacked bar chart when:

  • You want to compare relative contributions

  • Total values differ but composition matters

  • You want to visualize distribution changes over time

  • Absolute numbers are less important than percentage share


๐Ÿ”น Example Scenario

Imagine you are analyzing Product A vs Product B sales over different years.
Even if total sales change each year, this chart helps you understand:

  • Which product dominates each year

  • How the market share shifts over time


๐Ÿ”น Key Idea Behind It

๐Ÿ‘‰ Every bar equals 100%
๐Ÿ‘‰ Data is normalized into percentages
๐Ÿ‘‰ Makes proportional comparison easier and clearer


๐Ÿ”น Python Code (Percentage Stacked Bar Chart)

import matplotlib.pyplot as plt import numpy as np
years = ['2022', '2023', '2024'] product_a = np.array([50, 70, 40]) product_b = np.array([50, 30, 60])
total = product_a + product_b a_percent = product_a / total * 100 b_percent = product_b / total * 100
x = np.arange(len(years)) plt.bar(x, a_percent, label='Product A') plt.bar(x, b_percent, bottom=a_percent, label='Product B') plt.xlabel('Year') plt.ylabel('Percentage')
plt.title('Percentage Stacked Bar Chart') plt.xticks(x, years) plt.legend()
plt.show()

๐Ÿ”น Output Explanation

  • Each bar represents one year

  • The full height of every bar is 100%

  • Blue and orange segments show percentage contribution

  • Easy to compare which product has a higher share each year


๐Ÿ”น Stacked Bar Chart vs Percentage Stacked Bar Chart

FeatureStacked Bar ChartPercentage Stacked Bar Chart
ShowsActual valuesPercentage values
Bar heightVariesAlways 100%
Best forTotal comparisonProportion comparison

๐Ÿ”น Key Takeaways

  • Percentage stacked bar charts focus on relative importance

  • Ideal for composition analysis

  • Helps compare distribution, not magnitude

  • Very useful for market share & survey 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)