Python Central HubSign in

Data Analytics with Python / Phase 7: Interactive Visualization with Plotly

Sunburst Charts

Visualize hierarchical data (category → subcategory) using interactive sunburst charts.

When to use sunburst charts

Sunburst charts are for hierarchical breakdowns, where each level nests inside the one before it:

  • Region → City → Store
  • Category → Subcategory → Product

The center ring is the top of the hierarchy; each ring further out is one level deeper. A segment's angle (arc width) is proportional to its value, so you can see both "how big is this branch" and "how does it split further" in one picture. Use sunbursts when the hierarchy itself is part of the story — not just as a fancier pie chart.

Example

Python
import pandas as pd
import plotly.express as px
 
df = pd.DataFrame({
    "region": ["West", "West", "North", "North"],
    "city": ["Pune", "Mumbai", "Delhi", "Chandigarh"],
    "sales": [120, 90, 180, 60],
})
 
fig = px.sunburst(df, path=["region", "city"], values="sales", title="Sales hierarchy")
fig.show()

path=["region", "city"] tells Plotly the nesting order (outermost group first); values="sales" sizes every arc. Clicking a ring segment in the rendered chart zooms into that branch — a built-in drill-down for free.

sketch Sunburst = concentric rings, one per hierarchy level p5.js
The inner ring is region, the outer ring is city — each arc's width is proportional to its sales value.

Tip

If your hierarchy is large, sunburst can become cluttered — thin outer rings become unreadable slivers. Consider bar charts (or a treemap) for top-level summaries, and reserve the sunburst for cases where the drill-down interaction genuinely helps.

diagram Building a sunburst mermaid
Each path level becomes one ring; the ring's arcs are sized by the values column.

Check your understanding

quizCheck yourself
  1. What does path=["region", "city"] define in px.sunburst?

    Show answer

    B — The nesting order, outermost group first — The first item is the inner ring and the next level nests inside it.

  2. What determines the arc width of a segment?

    Show answer

    B — Its value, here the sales column — values="sales" sizes every arc, so angle is proportional to value.

  3. In the sunburst, which ring is the top of the hierarchy?

    Show answer

    A — The center ring — The center is the top level and each ring further out is one level deeper.

  4. A very large hierarchy produces unreadable slivers. What does the lesson suggest?

    Show answer

    C — Use bar charts or a treemap for top-level summaries — Sunbursts get cluttered with many categories, and a handful of children per level works best.

Next

Continue to: 3D Scatter Plots for exploring three numeric variables at once.

🧪 Try It Yourself

Exercise 1 – Define the Hierarchy Path

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Size Arcs by a Value Column

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Three-Level Hierarchy

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did