Thursday, 19 March 2026

๐ŸŒž Day 29: Sunburst Chart in Python

 

๐ŸŒž Day 29: Sunburst Chart in Python

๐Ÿ”น What is a Sunburst Chart?

A Sunburst Chart is a circular hierarchical visualization where:

  • Inner rings represent parent categories

  • Outer rings represent child categories

  • Each segment’s size shows its proportion

Think of it as a radial treemap.


๐Ÿ”น When Should You Use It?

Use a sunburst chart when:

  • Your data is hierarchical

  • You want to show part-to-whole at multiple levels

  • Structure is more important than exact values

Avoid it for precise numeric comparison.


๐Ÿ”น Example Scenario

  • Company → Department → Team performance

  • Website → Section → Page views

  • Product → Category → Sub-category sales


๐Ÿ”น Key Idea Behind It

๐Ÿ‘‰ Center = top-level category
๐Ÿ‘‰ Rings expand outward for deeper levels
๐Ÿ‘‰ Angle/area represents contribution


๐Ÿ”น Python Code (Sunburst Chart)

import plotly.express as px
import pandas as pd
data = pd.DataFrame({
"category": ["Electronics", "Electronics", "Clothing", "Clothing"],
"subcategory": ["Mobiles", "Laptops", "Men", "Women"],
"value": [40, 30, 20, 10] }
) fig = px.sunburst(
data, path=['category', 'subcategory'],
values='value',
title='Sales Distribution by Category'
)
fig.show()

๐Ÿ“Œ Install Plotly if needed:

pip install plotly

๐Ÿ”น Output Explanation

  • Inner circle shows main categories

  • Outer ring breaks them into subcategories

  • Larger segments indicate higher contribution

  • Interactive (hover & zoom)


๐Ÿ”น Sunburst vs Treemap

AspectSunburstTreemap
ShapeCircularRectangular
Hierarchy clarityHighMedium
Space efficiencyMediumHigh
Visual appealHighMedium

๐Ÿ”น Key Takeaways

  • Best for hierarchical storytelling

  • Interactive charts work best

  • Avoid too many levels

  • Great for dashboards & reports


0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (221) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (28) Azure (9) BI (10) Books (262) Bootcamp (1) C (78) C# (12) C++ (83) Course (86) Coursera (300) Cybersecurity (29) data (5) Data Analysis (27) Data Analytics (20) data management (15) Data Science (325) Data Strucures (16) Deep Learning (134) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (66) Git (10) Google (50) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (263) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (13) PHP (20) Projects (32) Python (1266) Python Coding Challenge (1080) Python Mistakes (50) Python Quiz (447) 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)