'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.



Solution 1:[1]

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

Solution 2:[2]

I suggest an R package, ggsunburst https://github.com/didacs/ggsunburst

This might be a good starting point. The file data.txt contains the first four words in you example

library(ggsunburst)
sb <- sunburst_data('data.txt', type = "lineage", sep = ' ')
sunburst(sb, node_labels = T, node_labels.min = 0)

enter image description here

using the first four words in questions from https://conversationstartersworld.com/good-questions-to-ask/

sunburst(sb, node_labels = T, leaf_labels = F, node_labels.min = 5)

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Franck Dernoncourt
Solution 2