Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a sunburst plot from a list of strings in Python?

I have a list of strings:

How many glasses are on the tab ?
What does the sign say ?
Has the pizza been baked ?
Do you think the boy on the ground has broken legs ?
Is this man crying ?
How many pickles are on the plate ?
What is the shape of the plate?
…

How can I convert it into a sunburst plot in Python?

The sunburst plot shows the distribution of questions by their first four words, the arc length is proportional to the number of questions containing the word and the white areas are words with contributions too small to show.

enter image description here

(Image source -> page 5, figure 3)

The question How to make a sunburst plot in R or Python? doesn't make any assumption regarding the input format and the Python answers assume that the input has a very different format.

like image 826
Franck Dernoncourt Avatar asked Sep 05 '25 01:09

Franck Dernoncourt


1 Answers

Expanding on Jimmy Ata's answer, which pointed to the Python plotly package:


You can use https://plotly.com/python/sunburst-charts/:

Example from the same page:

# From https://plotly.com/python/sunburst-charts/
import plotly.express as px
data = dict(
    character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
    value=[10, 14, 12, 10, 2, 6, 6, 4, 4])

fig =px.sunburst(
    data,
    names='character',
    parents='parent',
    values='value',
)
fig.show()

enter image description here

like image 169
Franck Dernoncourt Avatar answered Sep 06 '25 20:09

Franck Dernoncourt