How to create a sunburst chart using matplotlib python

share link

by vsasikalabe dot icon Updated: May 3, 2023

technology logo
technology logo

Solution Kit Solution Kit  

Sunburst plots the elements to visualize data spanning outwards from root to leaves. The circle describes the node's root and the hierarchy moving outward from the center. The root starts from the center, adding children's elements to the outer rings. A ring chart, known as a sunburst chart, can help visualize the data represented by the circles. A sunburst diagram is like a TreeMap. 

Types of data that we can analyze with a Sunburst Chart:  

  • Financial data 
  • Social media data 
  • Health data 
  • Population data 
  • Education data 

We must build a hierarchy of levels to Sunburst charts. We will specify the colors using the color name of the plots. If it is not specified, we must pick the sector colors by (default trace color set). The Sunburst chart is also the Ring Chart, Multi-Level Pie Chart, or TreeMap. It is a better way to visualize and access hierarchical data. We can apply the corresponding color if a sector has the same value for all its children. But we can use the first color of the color sequence for the different values. We can use the parent parameter to provide each sector of the parent. Here, we are using the matplotlib library to plot the Sunburst chart. 


  • Intuitive & Easy to use: Once the data is ready, then your data and matplotlib. Up to two lines are necessary to generate the first plots. 
  • Flexible & Robust: Methods responsible for spacing, coloring, styling, etc., of the element. It allows the setting of most properties. 

More specifically:  

  • The positioning of labels is perfect, which depends on space. 

You can draw many plots with the subplot() function in one figure. The axis equals the aspect ratio, so the data elements are the same in every direction. We can change the x-, y-, and z-axis following the range of units in the x, y, and z directions. We can use the cmap for colormap and register with colormap name. A. By default, and different colormaps are available in matplotlib. NumPy arrange() is one of the array creations based on numerical ranges. It creates the ndarray with spaced values and returns its reference. 

The hierarchy of the Sunburst chart begins with the inner circle to the outer circle. It displays the relationship with each other. We must set the parent sectors. We have passed these color arguments to its children. The root of the Sunburst chart is 1st level. The branches are the second level, and the last level is the leaves of the Sunburst charts. We need to install the NumPy library for the arithmetic operations. You can also use Jupyter Notebook to access the following code. 

Here is an example of how to create a sunburst chart using matplotlib python: